gpt4 book ai didi

ios - Firebase Auth Google - 始终询问帐户

转载 作者:行者123 更新时间:2023-12-05 05:10:33 25 4
gpt4 key购买 nike

我最近实现了谷歌登录。它工作正常,但有一件事困扰着我。

当用户第一次登录时,会打开一个窗口供用户登录 google 并选择他的帐户。但是,当用户注销并再次尝试通过 google 登录时,会以某种方式记住他之前的登录,而他刚刚登录。

每次用户选择通过 google 登录时,如何实现要求 google 登录?

这就是我注销用户的方式:

 try! Auth.auth().signOut()

登录:

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
if let error = error {
print("Failed logging into Google: ", error)
return
}

print("Successfully logged into Google.")

guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)

Auth.auth().signIn(with: credential) { (acc, error) in
if let error = error {
print("Failed to create User with Google: ", error)
return
}

let databaseRef = Database.database().reference()
guard let uid = Auth.auth().currentUser?.uid else { return }
databaseRef.child("users").observeSingleEvent(of: .value, with: { (snapshot) in

if snapshot.hasChild("\(uid)") {
print("Data found.")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
vc.readLeasing()
vc.readData()
} else {
self.upDataToDatabase(from: user)
}

})

let defaults = UserDefaults.standard

logInViaGoogle = true
defaults.set(logInViaGoogle, forKey: "logInViaGoogle")

print("Successfully created user with Google.")
}
}

最佳答案

Firebase google auth automatically selecting user. How to force it to select account 中所述

你可以这样做

var provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({
prompt: 'select_account'
});

关于ios - Firebase Auth Google - 始终询问帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56505508/

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