Why is the user email verified all the time?
I do not know why the user email still verifying and reload function return true even when I do not verify the email, but i receive mail.
import "package:firebase_auth/firebase_auth.dart";
import "package:firebase_core/firebase_core.dart";
import "package:flutter/material.dart";
import "package:my_chat_app/View/pages/home.page.dart";
import "package:my_chat_app/View/pages/login.page.dart";
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "AIzaSyBKZ_8PVfbb_VwHw4P8yTMcFOH6zoM_oZE",
appId: "1:36434956024:android:60204da7a7e7c1877a750d",
messagingSenderId: "messagingSenderId",
projectId: "chat-app-27389"),
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
User? user = FirebaseAuth.instance.currentUser;
Future<bool> reload(User user) async {
await FirebaseAuth.instance.currentUser?.reload();
return user.emailVerified;
}
@override
Widget build(BuildContext context) {
User? user = FirebaseAuth.instance.currentUser;
return MaterialApp(
debugShowCheckedModeBanner: false,
home: user != null && reload(user) == true
? const HomePage()
: LoginPage());
}
}
This is the implementation of the sign in/up method:
When the user press login button :
MyBotton(
btnText: "Login",
onTap: () {
reload();
if (_formKey.currentState!.validate()) {
firebaseServices!.loginWithEmailPassword(
emailController.text,
passwordController.text,
context);
}
},
),
2
Answers
It depends on the sign-in methods used. if the user uses Google sign-in, then emailVerified will always return true, if that is not the case then provide the code that shows the sign-in methods implemented. Also, could you take out your apiKey from the post or any public view… that is dangerous
Your
reload
is an asynchronous method that returnsFuture<bool>
. That means thatreload(user) == true
should not even compile in this code:If you want to use a
Future
while building a UI, you need to use aFutureBuilder
.