Firebase authentication token expiration with Next.js SSR

Viewed 414

I have a Next.js app with Firebase authentication. I store the JWT in a cookie so that it can be accessed on the server side from getServerSideProps. However, since Firebase tokens expire every hour, if I leave the app open for more than an hour the token doesn't refresh automatically and if I go to refresh the page I cannot retrieve data because my token has expired and I get a 401 unauthorized.

I also can't refresh my token since firebase.auth().currentUser.getIdToken is only available on the client side, and I can't reach client side because I am unauthorized. How can I refresh my token on the server side?

I tried Firebase Admin but the JWT has a different issuer and audience.

0 Answers
Related