vuejs / vuefire

🔥 Firebase bindings for Vue.js
https://vuefire.vuejs.org
MIT License
3.85k stars 332 forks source link

Refresh token if expired #1376

Closed luc122c closed 1 year ago

luc122c commented 1 year ago

What problem is this solving

Currently, when Firebase reports an expired token (auth/id-token-expired), vuefire simply logs the error.

Proposed solution

When the server component encounters this error, it could pass a message to the frontend to refresh the token. This can be achived with getIdToken($user, true).

Describe alternatives you've considered

Logging out and in again also clears the issue.

posva commented 1 year ago

Can you dive a bit more in the proposed solution?

luc122c commented 1 year ago

Sure. Althrough I'm not sure on the mechanism that Vuefire uses, the docs suggest that during SSR, data is serialised and then hydrated on the client side.

My suggestion would be that if the token has expired, send some additional metadata using the same mechanism, then check for this on the client side. If it is detected by the client plugin, call getIdToken to refresh the token and update the cookie.

posva commented 1 year ago

I did a few changes to avoid the page to crash when the token expires. I think the firebase js sdk automatically refreshes the token (I tested this locally). Is there anything left to do?

luc122c commented 1 year ago

As long as the refreshed token gets updated in the cookie, then all should be good :) Thank you!