how to verify email and password flutter firebase
954
Firebase offers a function for checking if users are verified which I used in the code below.
Future<bool> login(
String email, String password) async {
final user = (await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password))
.user;
if (user.isEmailVerified) {
return true;
}
return false;
}
However, to use this function, you have first send an email verification to your users somewhere in the function you call when your users create an account. The function below will create the user and send a verification email and then return a FirebaseUser
when done.
Future<FirebaseUser> register() async {
await _auth
.createUserWithEmailAndPassword(email: email.trim(), password: password)
.then(
(result) async {
//send verifcation email
result.user.sendEmailVerification();
return result.user;
},
);
return null;
}
Author by
MrFlutter
Updated on December 22, 2022Comments
-
MrFlutter over 1 year
i'm new with flutter and i want to implement a log in screen on my application. for that i use flutter and firebase. the problem is that when anything in the email and password field the application access to the home. so i need to verify the email before get the access.
here is the code
thanks guys for help me,
onPressed: () { if (_formKey.currentState.validate()) { Future<String> check = logIn(); if (check != null) { Navigator.pushReplacement( context, MaterialPageRoute( builder: (BuildContext context) => HomePage())); } }
-
MrFlutter almost 4 yearshere is the code i use stackoverflow.com/questions/62659205/…
-
MrFlutter almost 4 yearsi need your help thaaank you
-
ByteMe almost 4 years@MrFlutter I've updated my answer accordingly. Try the code and please mark as the answer if it works
-
MrFlutter almost 4 yearscan you please tell me where can i modify on my code.
-
MrFlutter almost 4 yearsi still have the same problem with sign in when i use any email it get access to the home page.
-
ByteMe almost 4 years@MrFlutter change ` Future<String> check` to ` Future<bool> check` . Change
(check != null)
to(check == true)
. I've also updated the login() function in answer. -
MrFlutter almost 4 yearsthaaanks a lot for your help it works, could you please hep me in this question stackoverflow.com/questions/62666643/add-reward-points-flutter
-
MrFlutter almost 4 yearsi post the code of the random function, the problem here is that i don't have an idea how can i make rewards point with flutter could you please give me a suggestion.