javascript - firebase.auth().createCustomToken is undefined on web app -


i'm trying create "remember me" function web app uses firebase.

my goal when user clicks "remember me" , logs in successfully, authentication token stored using localstorage , logged in automatically on next visit (i prefer storing raw credentials in localstorage security purposes).

however, when tried call firebase.auth().createcustomtoken got error saying not exist. wrong approach or wrong function call firebase? thanks!

here sample of code:

var customtoken = firebase.auth().createcustomtoken(user.uid); localstorage.setitem("savedtoken", customtoken); 

then later plan use line sign in:

firebase.auth().signinwithcustomtoken(localstorage.getitem("savedtoken")).then(function() { 

firebase.auth().createcustomtoken available in server api.

to authenticate email & password , token session, try this:

firebase.auth().signinwithemailandpassword(email, password)   .then(function(user) {     user.gettoken().then(function(token) {       localstorage.setitem("savedtoken", token); // store token     });   })   .catch(function(error) {     // handle error...   }); 

this work other authentication methods, too; use user.gettoken. later, if have token (still on client), , want authenticate it, just doing:

var token = localstorage.getitem("savedtoken"); // stored token firebase.auth().signinwithcustomtoken(token).catch(function(error) {   // handle error... }); 

the above code doesn't work, because signinwithcustomtoken works tokens minted server createcustomtoken. i'm not sure how auth email/password token.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -