nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
641 stars 98 forks source link

How come onIdTokenChanged is called with a delay? #457

Closed Flawe closed 3 years ago

Flawe commented 3 years ago

I have the following scenario:

  1. log in from laptop
  2. put laptop to sleep for 1 hour
  3. open laptop
  4. make call to api endpoint

At this point the user is still logged in but the idToken is expired. I tried something like this on the client side:

let res = await this.$axios.put('...', { ..., })
if (res.data.error === 'auth/id-token-expired') {
  await this.$fire.auth.currentUser.getIdToken()
  res = await this.$axios.put('...', { ..., })
}

But unfortunately both PUT calls end up returning auth/id-token-expired and only after those calls does my onIdTokenChanged action get called. Is there a way to deal with this without passing the token manually from the client side?

lupas commented 3 years ago

Hey @Flawe

Sorry for the late response - it's been a while, so I guess I can close this.

I think this option would have helped you: https://firebase.nuxtjs.org/service-options/auth#onidtokenchangedaction

Br, Pascal