sBourne sBourne - 3 months ago 67
iOS Question

Re-authenticating User Credentials Swift

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")
//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 = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)


let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)


let credential = FIRTwitterAuthProvider.credentialWithToken(session.authToken, secret: session.authTokenSecret)


let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken, accessToken: authentication.accessToken)