AndriousSolutions / auth

Other
47 stars 14 forks source link

`Auth.isEmailVerified` not returning true #1

Closed DanMossa closed 5 years ago

DanMossa commented 6 years ago

Hello!

I have a user create an account using Auth.createUserWithEmailAndPassword Auth.isEmailVerified returns false. I then send an email verification

Auth.sendEmailVerification();

The user then clicks on the email verification.

Auth.isEmailVerified still returns false.

Any ideas?

aqwert commented 5 years ago

Looking at the code, the reload method needs to be awaited.

static Future<bool> reload() async {
  await _user?.reload();
  return _setUserFromFireBase(_user);
}
DanMossa commented 5 years ago

Looking at the code, the reload method needs to be awaited.

static Future<bool> reload() async {
  await _user?.reload();
  return _setUserFromFireBase(_user);
}

That makes sense!

I guess I just don't really understand how to use async and await correctly then.

This is what I currently have

        if (_formKey.currentState.validate()) {
          Auth.signInWithEmailAndPassword(
                  email: emailAddressController.text,
                  password: passwordController.text)
              .then((onSuccess) {
            Auth.reload();
            if (Auth.isSignedIn()) {
              if (Auth.isEmailVerified) {
                Navigator.of(context).pop();
                Navigator.of(context).pushReplacementNamed(HomePage.tag);
              } else {
                Auth.sendEmailVerification();
                emailVerificationDialog(context);
              }
            }
          }).catchError((e) {
            print(" LSAHJDSAKHDSA " + e);
          });
        }

I just think it's an issue of me not knowing what I'm doing wrong?

aqwert commented 5 years ago

It is not your code that is the issue, but the library's.

Since reload is not marked as async when it executes _user?.reload() without await it will simply carry on synchronously and then it will get to your code if (Auth.isEmailVerified) { before it actually has done anything to firebase.

What I suggest until the library is fixed is to put a delay before you check the email is verified.

You can also convert your code to async await rather than use the then function

Andrious commented 5 years ago

await _user?.reload(); has been introduced.

Note, this library is not currently supported as described in the article, Auth in Flutter. However, this library will be formally supported in the near future.