B
B
bormor2019-09-17 11:58:02
JavaScript
bormor, 2019-09-17 11:58:02

Firebase - how to get user data by reading a token from LocalStorage?

There is a token in LocalStorage

const token = await firebase.auth().currentUser.getIdToken()
localStorage.setItem('token', token)

Reloaded the page, read the token.
How to check that the token is valid now?
How to upload user data?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Alexandrovich, 2019-09-17
@RomReed

Here is what I found for your question
so when you get a token you need to remember the time and check if its time has expired the next time you use it.
And here I found more material on how to get user data
https://firebase.google.com/docs/auth/web/manage-users

var user = firebase.auth().currentUser;
var name, email, photoUrl, uid, emailVerified;

if (user != null) {
  name = user.displayName;
  email = user.email;
  photoUrl = user.photoURL;
  emailVerified = user.emailVerified;
  uid = user.uid;  // The user's ID, unique to the Firebase project. Do NOT use
                   // this value to authenticate with your backend server, if
                   // you have one. Use User.getToken() instead.
}

V
Vladimir, 2019-09-17
@HistoryART

LocalStorage.getItem('token');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question