2016-08-01 27 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」。

相關問題