how to check if user has already signed up or not in firebase via google account in swift

泪湿孤枕 提交于 2019-12-10 22:36:48

问题


I want to do an action for user that login for the first time (signed up) using google account and another action if the user has already login before.

if some user has been and still logged in using their Google account, we can use this lines of code

Auth.auth().addStateDidChangeListener { (auth, user) in
    if user == nil {
        self.goToLoginVC()
    }
}

but how can I differentiate if a user login for the first time (signed up) or not ? is there any particular method to accomplish this? Thanks


回答1:


You can use UserDefault to check the same. Just maintain the flag to check

like

    GIDSignIn.sharedInstance().signInSilently()


   Auth.auth().addStateDidChangeListener { (auth, user) in
        if user != nil {
             if UserDefaults.standard.string(forKey: "uid") != nil && Auth.auth().currentUser != nil {
              //User was already logged in 
               }

             UserDefaults.standard.setValue(user?.uid, forKeyPath: "uid")

            self.performSegue(withIdentifier: "CurrentlyLoggedIn", sender: nil)

        }
    }


来源:https://stackoverflow.com/questions/48335773/how-to-check-if-user-has-already-signed-up-or-not-in-firebase-via-google-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!