I wish to re-authenticate a user prior to allowing them to change their login information. However, due to the recent Firebase update, I found the documentation rather unhelpful. Using this link I produced the following authenticateUser() function.
func authenticateUser()
{
let user = FIRAuth.auth()?.currentUser
var credential: FIRAuthCredential
//prompt user to re-enter info
user?.reauthenticateWithCredential(credential, completion: { (error) in
if error != nil
{
self.displayAlertMessage("Error reauthenticating user")
}
else
{
//user reauthenticated successfully
}
})
}
However, I am unsure what to do with the credential variable of type FIRAuthCredential, in order to re-authenticate the user. The documentation for this class can be found here.
Getting the FIRAuthCredential
object depends on what provider you want to use to reauthenticate.
let credential = EmailAuthProvider.credential(withEmail: email, password: password)
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.currentAccessToken().tokenString)
let credential = TwitterAuthProvider.credential(withToken: session.authToken, secret: session.authTokenSecret)
let authentication = user.authentication
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With