Firebase Auth Google-始终要求提供帐户

时间:2019-06-08 10:26:07

标签: ios swift firebase firebase-authentication

我最近实现了google登录。它可以正常工作,但是有一件事困扰着我。

当用户首次登录时,将打开一个窗口供用户登录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.")
    }
}

1 个答案:

答案 0 :(得分:0)

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

你可以做

SORT t_patient_list[] BY kunnr.

LOOP AT lt_cov_entry[] ASSIGNING FIELD-SYMBOL(<ls_cov_entry>).
  READ TABLE t_patient_list[]
      ASSIGNING FIELD-SYMBOL(<fs_patient_list>)
      WITH KEY kunnr = <ls_cov_entry>-kunnr
      BINARY SEARCH.

  IF sy-subrc <> 0.
    CLEAR ls_patient_record.
    MOVE-CORRESPONDING <ls_cov_entry> TO ls_patient_record.
    INSERT ls_patient_record INTO t_patient_list[] INDEX sy-tabix.
  ELSE.
    <fs_patient_list>-hosp_type = <ls_cov_entry>-hosp_type.
  ENDIF.
ENDLOOP.