Prevent multiple devices from using the same Firebase account through Swift

最后都变了- 提交于 2019-12-10 15:54:49

问题


I'm building an iOS app using Swift and Firebase for authentication that needs to avoid multiple connections of the same account from different devices. I've read some other posts on here but haven't found a definitive answer as to why this isn't working. I first tried checking to see if the current user is nil with the below code (which always shows nil due to async calling).

    if Auth.auth().currentUser == nil { 
    // ...
    }

I also tried using the addStateDidChangeListener() callback function in my viewDidLoad() and while it does fire when a sign in occurs, it still doesn't return any currently connected sessions or show the current user as already signed in when I login with the same credentials on a different device.

    Auth.auth().addStateDidChangeListener { (auth, user) in
    // ...
    }

Is there a better way to check if the account I'm trying to sign into firebase with is currently signed in already (or NOT signed out of a previous session)?

来源:https://stackoverflow.com/questions/46163974/prevent-multiple-devices-from-using-the-same-firebase-account-through-swift

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