当前位置: 首页 > 知识库问答 >
问题:

Firebase/Flutter: reload() not refreshing user.isEmailVerified

慕容恩
2023-03-14

当用户在应用程序中注册时,我会发送一个验证链接,但当我尝试创建一个流以侦听用户单击电子邮件中的验证链接时。

我知道我需要以某种方式刷新用户令牌,但似乎无法使其工作。我以为<code>reload()

问题是,流总是返回isEmailVerified == false,唯一使其为真的方法是用户注销并再次登录,这是我希望避免的。我该怎么做?

我创造了这个未来:

//CHECKS IF EMAIL IS VERIFIED
  Future<bool> checkIfEmailIsVerified() async {
    FirebaseUser currUser = await _auth.currentUser();
    await currUser.reload();
    currUser = await _auth.currentUser();
    final bool flag = currUser.isEmailVerified;

    if (currUser != null) {
      return flag;
    } else {
      return false;
    }
  }

而这个流:

//IS EMAILVERIFIED STREAM
  Stream<EmailVerified> get emailVerified async* {
    final bool isEmailVerified = await checkIfEmailIsVerified();
    yield EmailVerified(isEmailVerified);
  }

共有2个答案

方斌
2023-03-14

尝试使用单个等待链接期货

FirebaseUser currUser = await _auth.currentUser().then((u) => u.reload().then((_) => _auth.currentUser()));
final bool flag = currUser.isEmailVerified;
西门靖琪
2023-03-14

不幸的是,有必要在重新加载后获取用户的新实例:

User user = FirebaseAuth.instance.currentUser;
if (user != null) {
    await user.reload();
    user = FirebaseAuth.instance.currentUser;
    if (user.emailVerified) {
      ...
    }
}
 类似资料:
  • Firebase is a Backend-as-a-Service (BaaS) app development platform that provides hosted backend services such as a realtime database, cloud storage, authentication, crash reporting, machine learning,

  • @nativescript/* plugins npm run setupnpm start @nativescript/firebase-admob @nativescript/firebase-analytics @nativescript/firebase-app-check @nativescript/firebase-auth @nativescript/firebase-core @n

  • firebase-ruby 是 Firebase 后端 API 的 Ruby 语言封装。 示例代码: Firebase.base_uri = 'https://<your-firebase>.firebaseio.com/'response = Firebase.push("todos", { :name => 'Pick the milk', :priority => 1 })response.

  • Firestorm 是一个 firestore 的 TypeScript ORM 框架。 示例代码: import * as firestorm from 'firebase-firestorm';...const firestore = firebase.initializeApp(...);firestorm.initialize(firestore, /* options */);@root

  • Firebase for Laravel A Laravel package for the Firebase PHP Admin SDK. Installation Laravel Lumen Configuration Usage Multiple projects Upgrading Support License Installation This package requires Lar

  • FirebaseCMS FirebasCMS is an e-commerce and blogging platform with a storefront and CMS built with Angular 4 (Angular CLI), Firebase (AngularFire2), Angular Material and Stripe. Create, moderate and m

  • Expo Firebase Instagram Made with Expo & Web Firebase SDK Tutorial: https://blog.expo.io/instagram-clone-using-firebase-react-native-expo-cc32f61c7bba Getting Started Download with: git clone https://

  • Awesome Firebase The most up to date list of Firebase docs, talks, tools, examples & articles the internet has to offer. Translations: ���� en · ���� ko · ���� ru Firebase is an app dev platform built