Reputation: 63
I'm using firebase for my web project, and want to allow users to delete their account, which requires reauth according to Firebase. I've been having a lot of trouble getting their user.reauthenticateAndRetrieveDataWithCredential
to work.
Specifically, I'm not sure how to generate an AuthCredential
to pass to it using the GoogleAuthProvider.credential()
method, since I don't know how to get a user's ID token or access token.
I've tried user.getIdToken()
(here) which gives me an error that the credential is not issued by Google.
Asking the user to sign in again with a popup and then taking the res.credential
accessToken or idToken works, but then allows them to sign in to a different user at that time which is not what I want.
Any tips on how to get a valid idToken from the currently logged in user for reauthentication?
Thanks!
Upvotes: 4
Views: 2793
Reputation: 30798
Just use reauthenticateWithPopup
/reauthenticateWithRedirect
.
firebase.auth().currentUser.reauthenticateWithPopup(new firebase.auth.GoogleAuthProvider())
.then(function(userCredential) {
// You can now delete the user:
return firebase.auth().currentUser.delete();
})
.catch(function(error) {
// Credential mismatch or some other error.
});
Upvotes: 6