我试图在iOS上的Swift中取消用户的电子邮件/密码身份验证。我已阅读the documentation并设法链接和取消链接Facebook身份验证,没有任何问题。但是,成功链接电子邮件/密码凭据后,providerData
对象为零。 providerID
是" Firebase"但是当我将其传递给unlink代码时,会抛出以下错误:
Error Domain=FIRAuthErrorDomain Code=17016 "User was not linked to an account with the given provider." UserInfo={NSLocalizedDescription=User was not linked to an account with the given provider., error_name=ERROR_NO_SUCH_PROVIDER}
我使用的取消链接代码是:
let providerId = (FIRAuth.auth()?.currentUser?.providerID)!
print("Trying to unlink:",providerId) // providerId = "Firebase"
FIRAuth.auth()?.currentUser?.unlinkFromProvider(providerId) { user, error in
if let error = error {
print("Unlink error:", error)
} else {
// Provider unlinked from account successfully
print("Unlinked...user.uid:", user!.uid, "Anonymous?:", user!.anonymous)
}
}
阅读文档并让它适用于Facebook,我希望在电子邮件身份验证之后,可以使用某些内容填充providerData数组。那么我的链接代码是错误的(它不会抛出错误并且似乎工作正常)?
我的关联代码:
let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)
FIRAuth.auth()?.currentUser!.linkWithCredential(credential) { (user, error) in
if user != nil && error == nil {
// Success
self.success?(user: user!)
dispatch_async(dispatch_get_main_queue(), {
self.dismissViewControllerAnimated(true, completion: nil)
if type == "new" {
print("New user logged in...")
}
if type == "existing" {
print("Existing user logged in...")
}
})
} else {
print("Login error:",error)
self.showOKAlertWithTitle("Login Error", message: error!.localizedDescription)
}
}
关于如何修改我的方法的任何指示都会很棒。
答案 0 :(得分:1)
要从与用户关联的登录提供程序中检索配置文件信息,请使用providerData属性。
if let user = FIRAuth.auth()?.currentUser {
for profile in user.providerData {
// Id of the provider (ex: facebook.com)
let providerID = profile.providerID
}
} else {
// No user is signed in.
}
调用FIRAuth.auth()?currentUser?.providerID将导致" firebase"。