Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create “credential” object needed by Firebase web user.reauthenticate() method?

var user = firebase.auth().currentUser;
var credential;
// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential).then(function() {

With the v3 Firebase client, how should I create this credential object for Google auth provider (Not email & Password).

How to do it with email and password was answered here: Email&Password.

I've tried var credential = firebase.auth.GoogleAuthProvider.credential(); but according to the docs it's needs an "Google Id Token" which I have no idea how to get.


1 Answers

You can create an AuthCredential by using firebase.auth.EmailAuthProvider.credential.

Then you can reauthenticate with firebase.User.reauthenticateWithCredential.

var user = firebase.auth().currentUser;
var credential = firebase.auth.EmailAuthProvider.credential(
  user.email,
  'yourpassword'
);
user.reauthenticateWithCredential(credential);
like image 190
Rohmer Avatar answered Jul 31 '26 21:07

Rohmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!