如何通过Google帐户快速检查用户是否已在Firebase中注册 [英] how to check if user has already signed up or not in firebase via google account in swift

查看:104
本文介绍了如何通过Google帐户快速检查用户是否已在Firebase中注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为使用Google帐户首次登录(注册)的用户执行一项操作,如果该用户之前已经登录,则执行另一项操作.

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.

如果某些用户已经并且仍然使用其Google帐户登录,我们可以使用以下代码行

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

推荐答案

您可以使用UserDefault进行检查.只需维护该标志即可检查

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

喜欢

    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)

        }
    }

这篇关于如何通过Google帐户快速检查用户是否已在Firebase中注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆