How to refresh firebase token on server side #1372
-
Hello, how can I refresh a firebase token after it has been expired on the nuxt server side? For requests i use vue apollo client (https://github.com/vuejs/apollo) After the user has not visited the site, the token is expiring (token expires after 1 hour). When a user tries to re-enter the site, a request is made with the old token and consequently falls with an error, after the request has fallen with an error, I try to refresh the token in OnError and repeat the request, but the token can only be refreshed on the client side, what is the best way to solve this problem? Now it only comes to my mind to wait with the subscriber in OnError when there is a client side and call a chain of requests there, but this is not the most pleasant way, since when the page loads the user will see a request error and only on the client side it will disappear Thanks for any help |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
One solution might be to create a page that updates the token and then return to the original page. It will look something like this:
However, the problem is not completely solved yet, if your middleware has a check to see if the user exists, then it will fail. To process this case, we need to know if the token passed the check on the server, I suggest forwarding the error further so that even without the user it is possible to understand that the error is that the token is expiring. In such a solution, it will be possible to process all cases, but if I throw an error in nuxt.payload, I don’t understand how to make this error clear when the token is updated, what you think, @posva . I will make pull request when we decided to best approach for this problem ![]() |
Beta Was this translation helpful? Give feedback.
-
I could be wrong but AFAIK you can only generate those on the client: |
Beta Was this translation helpful? Give feedback.
The relevant code doesn't throw anymore, it just considers the user logged out. With the correct redirections, the user is logged in again on the client and then redirected to the page they wanted to visit in the first place. The nuxt/playground does this and I have plans to add more docs around this