8

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

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
AnthonyZ
  • 81
  • 4
  • 2
    Since it has to do with multiple devices your most likely going to have to set a flag in firebase indicating whether the account is already signed in somewhere else and then checking it on the device when they attempt to sign on. I don't think firebase itself limits logins to one session per account. – JustinM Sep 12 '17 at 01:03
  • That makes a lot of sense Justin, I was hoping firebase auth kept track of signins but handling it myself looks like it might be the way to go. – AnthonyZ Sep 12 '17 at 01:16

0 Answers0