Re-authenticating User Credentials Swift

In Swift 4 and latest firebase 4 the names have changed a bit, but the principle still remains. For your convenience:

    let eMail = EmailAuthProvider.credential(withEmail: "[email protected]", password: "somepassword")
    let fb = FacebookAuthProvider.credential(withAccessToken: "xxx")
    let g = GoogleAuthProvider.credential(withIDToken: "xxx", accessToken: "xxx")
    ...

    Auth.auth().currentUser?.reauthenticate(with: eMail, completion: {
        [weak self]
        (error) in
        ...
    })

Firebase's documentation is currently outdated. Here is the correct way to handle reauthenticate.

let user = Auth.auth().currentUser

user?.reauthenticate(with: credential, completion: { (result, error) in
   if let err = error {
      //..read error message             
   } else {
      //.. go on              
   }
})

Getting the FIRAuthCredential object depends on what provider you want to use to reauthenticate.

Email:

let credential = EmailAuthProvider.credential(withEmail: email, password: password)

Facebook:

let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.currentAccessToken().tokenString)

Twitter:

let credential = TwitterAuthProvider.credential(withToken: session.authToken, secret: session.authTokenSecret)

Google:

let authentication = user.authentication
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)