[英]how to check if user has already signed up or not in firebase via google account in swift
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 如果某个用户已经并且仍然使用他们的Google帐户登录,我们可以使用这行代码
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
谢谢
You can use UserDefault
to check the same. 您可以使用
UserDefault
来检查相同内容。 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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.