Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase what should I do after idToken expires

I'm using onAuthStateChanged:

this.unregisterAuthObserver = firebase.auth().onAuthStateChanged(user => {
  if (user) {
    user.getIdToken(true).then((idToken) => {
      console.log(user)
      ...
    });
  }

When logged user becomes idle for 1hour idToken expires. What should I do after idToken expires? Trying to show some UI to users. Show modal to let the user know that session expired? or maybe reload page location.reload()?

Also is it possible to get idToken expiration time? console.log(user) doesn't get me expiration time

like image 829
test Avatar asked Jan 06 '19 02:01

test


1 Answers

You will want to use onIdTokenChanged(). As described in the API documentation:

Adds an observer for changes to the signed-in user's ID token, which includes sign-in, sign-out, and token refresh events.

The token refresh events are what you're interested in.

But you don't need to do anything when the token expires. Firebase Authentication will refresh it for you automatically, seamlessly.

like image 82
Doug Stevenson Avatar answered Oct 19 '22 11:10

Doug Stevenson