簡體   English   中英

linkWithCredential 和 linkWithPopup 有什么區別

[英]What's the difference with linkWithCredential and linkWithPopup

我閱讀了將匿名帳戶轉換為永久帳戶,並看到使用:

auth.currentUser.linkWithCredential(credential)

將合並匿名憑證和例如 Google、Facebook 等credential

然后我閱讀了使用 JavaScript 將多個 Auth Providers 鏈接到一個帳戶將使用以下方法執行相同的操作:

auth.currentUser.linkWithPopup(provider)

如果我的 SPA Reactjs 應用程序需要匿名登錄,之后有什么區別,我應該使用哪個,如果用戶想登錄,他可以使用 Google Facebook 來登錄。

我運行了一些測試,發現如果帳戶存在,使用linkWithPopup返回錯誤auth/credential-already-in-use那么我必須使用signInWithCredential 到目前為止,這工作正常。

閱讀有關linkWithCredential的信息,如果 Google 帳戶已在 Firebase 使用,我不知道該怎么辦。我認為linkWithCredential會創建兩個帳戶,所以我可能必須做我對linkWithPopup所做的事情,比如signInWithCredential

這兩個最終做同樣的事情; 什么時候使用什么,或者我錯過了什么?

linkWithCredential()將該帳戶與您從先前登錄中獲得的憑據相關聯。

linkWithPopup()將帳戶與給定的提供商鏈接,引導用戶完成該提供商的身份驗證流程。 憑據將自動從該登錄中獲取。

因此,如果您已經擁有用戶已登錄的帳戶的憑據,請使用linkWithCredential 如果您沒有用戶憑據,並且需要通過登錄流程使用 go 來獲取它們,請使用linkWithPopup()

無論哪種情況,最終結果都是相同的 - 當前登錄的 Firebase Auth 帳戶將鏈接到用戶已證明其身份的另一個帳戶(Google、Facebook 等)。

當社交身份驗證需要彈出窗口時, linkWithPopup()對於鏈接 Flutter Web 上的帳戶是必需的。 例如,如果您需要將 Apple 帳戶鏈接到現有帳戶, signInWithPopup()將進行身份驗證,創建一個新的 firebase 帳戶並返回新用戶......您不希望現有帳戶出現。

使用linkWithPopup() ,您可以驗證 apple 用戶和鏈接,跳過創建新帳戶和返回用戶的步驟。

如果將signInWithPopup()linkWithCredential()結合使用,則在大多數情況下(用戶返回並重建應用程序)您將永遠無法訪問linkWithCredential() ,或者您只會在鏈接嘗試時出錯,因為已創建新帳戶.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM