Prevent multiple devices from using the same Firebase account through Swift

I am building an iOS application using Swift and Firebase for authentication, which need to avoid multiple connections of the same account from different devices. I read some other posts here, but did not find a definitive answer on why this is not working. First I tried to check if there is a current user with the code below (which always shows nil due to an asynchronous call).

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

I also tried using the addStateDidChangeListener () callback function in my viewDidLoad (), and when it fires when a sign occurs, it still doesn't return any sessions that are currently connected, or showing the current user as already signed up when I login with the same credentials on another device.

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

Is there a better way to check if the account I am trying to log into firebase is currently signed up (or NOT logged out of a previous session)?

+4
source share

Source: https://habr.com/ru/post/1685490/


All Articles