简体   繁体   English

使用 Flutter 通过社交登录进行身份验证时如何获取用户详细信息?

[英]How to get user details when authenticating with social sign in with Flutter?

I am in the middle of creating a Flutter application and am stuck on how to implement authentication using email/password and social providers like Google and Facebook.我正在创建 Flutter 应用程序,并且一直在思考如何使用电子邮件/密码以及 Google 和 Facebook 等社交提供商实现身份验证。 Everything works except my approach on how to get user details to store in Firebase like address, phone number, username, etc. Implementing this when working with email/password registration has been simple because I created a multi screen form and then finally registered the user which would log them in. The problem with getting additional details when working with social providers is that I would need to authenticate the user first before ever getting the chance to get additional details.除了我关于如何将用户详细信息(如地址、电话号码、用户名等)存储在 Firebase 中的方法之外,一切都有效。在使用电子邮件/密码注册时实现这一点很简单,因为我创建了一个多屏幕表单,然后最终注册了用户这将使他们登录。与社交提供商合作时获取更多详细信息的问题是,在有机会获取更多详细信息之前,我需要先对用户进行身份验证。 How can I go about getting user details for users that choose to use Google and Facebook to authenticate?如何获取选择使用 Google 和 Facebook 进行身份验证的用户的用户详细信息?

One way is to prompt the user to enter the required additional details when the user logs in.一种方法是在用户登录时提示用户输入所需的附加详细信息。

You should first check if the user logged in through a Social Media provider :您应该首先检查用户是否通过社交媒体提供商登录:

List<String> providerList = await FirebaseAuth.instance.fetchSignInMethodsForEmail(_email);

fetchSignInMethodsForEmail will return a list of sign providers the user used to login to your app (if you haven't enabled account linking, this would probably be just one provider) fetchSignInMethodsForEmail将返回用户用于登录您的应用程序的签名提供程序列表(如果您尚未启用帐户链接,这可能只是一个提供程序)

Here's a list of social media provider ID's :以下是社交媒体提供商 ID 的列表:

GoogleAuthProviderID: google.com
FacebookAuthProviderID: facebook.com
TwitterAuthProviderID: twitter.com
GitHubAuthProviderID: github.com
AppleAuthProviderID: apple.com
YahooAuthProviderID: yahoo.com
MicrosoftAuthProviderID: hotmail.com

For example, if you have enabled Facebook login, you can check if the 'facebook.com' is available in the providerList , if so prompt a screen to collect your additional data and update your user record on Firestore for this user.例如,如果您启用了 Facebook 登录,您可以检查providerList 中的“facebook.com”是否可用,如果是,则提示一个屏幕以收集您的其他数据并更新您在 Firestore 上为该用户的用户记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM