为了在我的测试版应用程序中预注册某人,我通过电子邮件将他们添加到我的 Firebase Auth 用户。他们第一次打开应用程序时遇到登录挑战(到目前为止一切都很好)。他们使用“Google 登录”按钮登录并使用相同的电子邮件地址。 Firebase 允许他们进入,并使用我之前预先创建的相同授权用户。 (仍然很棒。)
问题是:当用户使用“Google 登录”登录时,他们的姓名和照片不会添加到他们的个人资料中。请记住,如果他们先使用“Google 登录”登录,我会捕获额外的个人资料信息,而且“Google 登录”似乎有效,但我似乎无法获得显示名称和照片。
有没有办法强制刷新个人资料信息,以便我可以提取他们的显示名称和照片?
(这是我在 Firebase 的“仪表板”中手动添加他们的电子邮件后使用的基本登录名)
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginStart), object: nil)
if let error = error {
print("Error while Google Sign In - \(error)")
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginFailure), object: nil)
return
}
// Google Authorisation
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
// Firebase Authorisation
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
print("Error while Firebase Auth - \(error)")
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginFailure), object: nil)
return
}
// Success
print("Firebase Login Successful.")
print("Firebase Login.", user!, user!.displayName ?? "No display Name")
FirebaseHelper.sharedInstance.updateUserDetails(uid: user!.uid, email: user!.email!, name: user!.displayName, avatar: user?.photoURL)
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginSucess), object: nil)
}
}
最佳答案
主要问题是您必须使用多个提供商。 默认情况下,用户对象将包含有关第一个经过身份验证的提供者的信息。在您的例子中,电子邮件提供商。
因此,当用户使用 facebook 登录时,配置文件不会更新这些详细信息,但详细信息(imageURL、名称、...)将被添加到 providerData
中,这是一个数组提供者数据。
因此您需要获取 providerData
中的最后一个条目或过滤
提供者编号
:
https://firebase.google.com/docs/auth/web/manage-users#get_a_users_provider-specific_profile_information
关于ios - 首次使用电子邮件登录后强制更新 Firebase 用户个人资料照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44490036/