Firebase custom token expiration in JavaScript

Viewed 363

I have implemented Firebase custom authentication using the firebase-admin library in Python on my server.

The first time I use the token, it works fine and I'm able to authenticate.

But if I restart my node.js application a few minutes later, I get the error:

The custom token format is incorrect. Please check the documentation.

Which I believe means that it has expired, even though I never logged out.

This does not seem to be working:

Once you've called authWithCustomToken successfully, you stay logged in forever (until you sign out explicitly) so you should be able to get devices to have a long-lived authentication session without minting long-lived custom tokens.

How do I explicitly save the authentication between application restarts? Or do I have to mint a new custom token on every restart?

1 Answers

Custom tokens are only valid for an hour. However, I'd suspect your caught error code to be something different. I'm personally on a quest to figure out how to best keep these tokens refreshed, but I do wonder if a deployed instance restarting might be an alternate cause of tokens being invalidated.

Related