I'm using Firebase Auth for my Swift iOS app. Google recommends using Firebase Auth UI as a "drop in" authentication system, but it only handles the initial login. I'm now working on allowing the user to make profile changes, such as email and password.
The documentation for making these changes mentions in several places that certain changes require the user to have logged in recently (see https://firebase.google.com/docs/auth/ios/manage-users#get_the_currently_signed-in_user):
Some security-sensitive actions—such as deleting an account, setting a primary email address, and changing a password—require that the user has recently signed in. If you perform one of these actions, and the user signed in too long ago, the action fails with the FIRAuthErrorCodeCredentialTooOld error.
First of all, there doesn't appear to be a FIRAuthErrorCodeCredentialTooOld
error anywhere in the API.
Second, the documentation suggests using reauthenticate(with:)
to solve this problem, with this code sample:
let user = FIRAuth.auth()?.currentUser
var credential: FIRAuthCredential
// Prompt the user to re-provide their sign-in credentials
user?.reauthenticate(with: credential) { error in
if let error = error {
// An error happened.
} else {
// User re-authenticated.
}
}
The problem is, because I used Firebase Auth UI, I have no custom UI for getting the user's credentials.
My current thinking is I could reauthenticate by presenting the same Firebase Auth UI used for logging in when this error occurs. However, I don't know if this is the sanctioned way to do this, or if it will work at all, or if it will continue to work in the future. I checked the Firebase Auth UI code base and there is no call to reauthenticate()
anywhere. The documentation makes a big deal of calling this method specifically in case of this error, so I'm confused.
If I need to build an entire UI to perform reauthentication, including multiple providers, what's the point of using Firebase Auth UI?