Reputation:
I send email verification and click the link. Then I call isEmailVerified()
on FirebaseUser
object. This always return null
, what may be the reason?
Upvotes: 19
Views: 10094
Reputation: 2762
I use something like this. It returns the local value if the local value is true (since once verified it should never get unverified), else it refreshes the user and returns the updated value.
var isEmailVerified: Bool {
get async {
if Auth.auth().currentUser?.isEmailVerified == true {
return true
}
try? await Auth.auth().currentUser?.reload()
return Auth.auth().currentUser?.isEmailVerified == true
}
}
Upvotes: 0
Reputation: 560
Same technique as @yehyatt´s solution but easier. Sign the user in with firebase, refresh the user and then check if the user is verified.
Sign the user In
Auth.auth().signIn(withEmail: YourEMail, password: YourPassword) { result, error in
if error != nil {
logInErrorReason = "\(error!.localizedDescription)"
// An error ocurred
}else {
// Handle successful login.
}
}
Refresh current user:
Auth.auth().currentUser?.reload(completion: ((Error?) -> Void)?)
Check if he is signed in:
if Auth.auth().currentUser?.isEmailVerified == true { // Handle successful verification}
Upvotes: 1
Reputation: 17
You will see your own account had already verified and can proceed next setps
https://github.com/FirebaseExtended/flutterfire/issues/2208
Upvotes: 0
Reputation: 106
First you have to call this method : signInWithEmailAndPassword
, at least 1 time after user has verified their email ....
Only after that, you will get isEmailVerified()
as true
Upvotes: 6
Reputation: 11
Re-authenticates the user who updates if the email has been verified ...
https://firebase.google.com/docs/auth/android/manage-users#re-authenticate_a_user
Upvotes: 1
Reputation: 210
isEmailVerified
should provide correct response, however you might be using it incorrectly.
So solution for this issue is to update you registration process.
When you create new user you should also issue a command to start email verification process await user.sendEmailVerification();
once your user will receive an email and will verify it. your method : user.isEmailVerified
will return true
Your registration process should look something like that:
AuthResult result = await _auth.createUserWithEmailAndPassword(
email: email,password: password);
FirebaseUser user = result.user;
await user.sendEmailVerification();
Upvotes: 0
Reputation: 2404
You should refresh the user object after verification as follows :
usertask = mAuth.getCurrentUser().reload();
usertask.addOnSuccessListener(new OnSuccessListener() {
@override
public void onSuccess(Void aVoid) {
user = mAuth.getCurrentUser();
boolean useremailveri = user.isEmailVerified();
String useremailuid = user.getUid();
}
});
Upvotes: 25
Reputation: 2188
I think you need to first login with user's Email and Password using signInWithEmailAndPassword
then try calling isEmailVerified()
method on returning user.
Upvotes: 0