[ad_1]
When i’m trying to login to Twitter, the function addStateDidChangeListener returns the user correctly, but then it’s executed several times returning null and therefore the session is closed.
This error only happens on iOS, on the web and Android it works perfectly.
Here’s the code
authStateDidChangeListenerHandle = Auth.auth().addStateDidChangeListener({ (auth, user) in
guard let user = user else {
print("User is signed out")
self.isUserAuthenticated = .signedOut
return
}
print("Successfully authenticated user with uid: \(user.uid)")
})
And the login function:
func signInWithTwitter() {
self.twitterProvider?.getCredentialWith(_: nil){credential, error in
if error != nil {
self.alertMessage = error!.localizedDescription
}
if let credential = credential {
Auth.auth().signIn(with: credential) { (authResult, error) in
if error != nil {
print(error)
}
guard let authResult = authResult else {
print("Couldn't get graph authResult")
return
}
print("Twitter user: " + authResult.user.uid)
}
}
}
}
[ad_2]