gpt4 book ai didi

ios - Firebase 匿名登录 - 为什么 FirebaseID 在登录到 Facebook 时发生变化,但在未登录到 Facebook 时保持不变?

转载 作者:行者123 更新时间:2023-11-28 13:25:33 24 4
gpt4 key购买 nike

我有以下允许 guest 用户登录我的应用程序的逻辑:

    (1) Login as Anonymous. 
(2) Check if Facebook is logged.
(3) If it is logged to Facebook, link to Anonymous.
(4) If link fails, Login to firebase passing facebook token to Firebase

如果我没有登录 Facebook,firebase 在步骤 (1) 之后给出的匿名 ID 始终相同。但是,我第一次登录 Facebook 时,按照步骤 (3) 将帐户链接到 firebase。从那时起,每次我通过登录过程时,我都会得到一个不同的匿名 ID。

问题 1.在我第一次登录 Facebook 之前,步骤 (1) 中的匿名 ID 是否始终相同?

问题 2.允许用户以访客身份在后台保存数据并在用户决定这样做后链接到 Facebook 的最佳登录流程是什么?

这是我实现伪代码的快速代码:

func login() -> Promise<AuthCredential?> {
// Login as Anonymous. Check if FB is logged. If it is, link to Anonymous. If fails, pass FB token to Firebase
print("........................")
print("Starting Login")
return Promise { seal in
Auth.auth().signInAnonymously() { (authResult, error) in
print("-Done Login Anonymously", authResult?.credential, Auth.auth().currentUser?.uid)
if let error = error {
print("-DID NOT SIGNED UP WITH FIREBASE:", error)
seal.reject(error)
} else {
if AccessToken.isCurrentAccessTokenActive { // If Facebook token is active exchange for Firebase

let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current!.tokenString)
print("-Loggged with FACEBOOK!!!!", credential)
Auth.auth().currentUser!.link(with: credential) { (result, error) in
print("-Linked Account!!!!??????????", result as Any, error as Any)
if error != nil {
Auth.auth().signIn(with: credential) { (authResult, error) in
print("-Signed UP in Firebase USIG FB. No Linking")
if let error = error {
print("-DID NOT SIGNED UP WITH FIREBASE:", error)
seal.reject(error)
} else {
print("-DID SIGNED UP WITH FIREBASE using FB:", Auth.auth().currentUser?.uid)

seal.fulfill(authResult?.credential)
}
}
}
}
}
// print("-Done Login", Auth.auth().currentUser?.uid)
// seal.fulfill(authResult?.credential)
}
}
}
}

最佳答案

signInAnonymously 的 API 文档(javascript) 读取:

If there is already an anonymous user signed in, that user will be returned; otherwise, a new anonymous user identity will be created and returned.

您可能只想在没有用户登录应用程序时调用 signInAnonymously。最好等一下,看看用户是否已经使用身份验证状态监听器登录,因为登录过程不是即时的。

一旦您将匿名帐户与完整帐户相关联,您可能不应该再次调用 signInAnonymously,因为您可能希望用户使用他们的完整帐户保持登录状态并且不创建另一个新的匿名帐户。

关于ios - Firebase 匿名登录 - 为什么 FirebaseID 在登录到 Facebook 时发生变化,但在未登录到 Facebook 时保持不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58416247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com