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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With