Firebase:如何检查用户是否已存在

时间:2021-03-15 18:56:26

标签: firebase flutter firebase-authentication

我使用 firebase 设置了 microsoft login 身份验证,这是我的登录函数中的代码:

User user = await FirebaseAuthOAuth().openSignInFlow(
          "microsoft.com", ["email openid"], {'tenant': 'common'});

现在我想将一些数据存储到 firestore,如果这是用户第一次登录,我该如何实现?

2 个答案:

答案 0 :(得分:1)

无法从 firebase 检查经过身份验证的用户,您必须在第一次对其进行身份验证时在数据库中注册用户,并从该数据库中检查用户是否存在。

答案 1 :(得分:0)

我建议您根据 Firebase Auth 上新添加的 API 尝试这些..

AdditionalUserInfo -> isNewUser → bool

UserMetadata -> creationTime → DateTime?