本文介绍了在电子邮件中验证邮件时,不会调用onAuthStateChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户注册我的应用程序时,他会收到一封验证电子邮件.当使用createUserWithEmailAndPassword创建用户时,会调用onAuthStateChanged -listener,但在验证电子邮件后不会调用.

When a user signs up in my app he gets a verification e-mail. The onAuthStateChanged-listener gets called when a user gets created using createUserWithEmailAndPassword but not after the email got verified.

我有一个单独的类来处理所有身份验证.以下方法是注册用户

I have a separate class which handles all authentications. The following method is to sign up user

Future<FirebaseUser> signUpUser(email, password) async {
final FirebaseUser user = await _auth.createUserWithEmailAndPassword(email: email, password: password);

assert (user != null);
assert (await user.getIdToken() != null);

return user;
}

使用此方法在我的StatefulWidget中调用此方法

This method is called in my StatefulWidget using this method

void _signUpUser() async {
try {
  await Auth().signUpUser(_email, _password)
    ..sendEmailVerification();
} catch (e) {
  print(e.toString());
}
}

在我的StatefulWidget

  FirebaseAuth.instance.onAuthStateChanged.listen((user) {
  print("Auth State Changed!");
  if (user.isEmailVerified) {
    print("EMail verified!");
  }
  }

推荐答案

onAuthStatechanged仅在用户登录或注销时触发.不在电子邮件验证上.

onAuthStatechanged is triggered only in case of user Login or Logout & not on Email verification.

按照文档-

onAuthStatechanged为更改用户登录状态添加观察者.

onAuthStatechanged Adds an observer for changes to the user's sign-in state.

观察者将在以下情况下触发:

The observer will be triggered in the following scenarios:

  • 这篇关于在电子邮件中验证邮件时,不会调用onAuthStateChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    11-02 20:40