2016-08-01 28 views
2

我试图从iOS中的Swift用户取消链接电子邮件/密码验证。我读过the documentation,并设法链接和取消连接Facebook身份验证,没有任何问题。但是,成功链接电子邮件/密码凭证后,providerData对象为零。该providerID是“火力地堡”,但是当我传递到取消链接代码以下错误被抛出:从iOS用户的Firebase取消链接电子邮件/密码验证

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) 
    } 
} 

的我怎么能修改我的做法任何指针将是巨大的。

回答

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”。

相关问题