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

标签 ios swift firebase firebase-authentication

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

当用户第一次登录时,会打开一个窗口供用户登录 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/

相关文章:

ios - 从 UIViewController 更改 UIWindow backgroundColor?

ios - 如何保存照片和文字

ios - 迪尔德 : Symbol not found: __TWPVs11AnyHashables20_AnyHashableProtocols

firebase - 托管多个站点的firebase配置.firebaserc文件

php - initWithObjects Keys for JSON POST to MySQL via PHP - 在数据库中获取空行

iphone - NS正则表达式 : Replace url text with <a> tags

arrays - 数组如何通过 Swift 按多个属性排序?

swift - Firebase 之类的系统无法正常工作

javascript - 火存储 : Multiple conditional where clauses

javascript - 批量获取DocumentReferences?