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)?