0

We are using firebase authentication with OTP for authenticating users into an android app and also for the chat and other firebase features. The chat is stored in a real-time database.

It's a services app where users buy services from service providers. The app normally stays logged in for weeks and months. However, the firebase user starts returning null if the user opens the app later. (firebase token expires after one hour)

I have read many articles that the firebase token can be refreshed just before it expires or upon expiry. However in our situation, when the user comes back, the token has already expired and it can no longer refresh the token. the getIdToken or any other methods do not work if the token has already expired.

One way would be to check every hour or 40 minutes to refresh the token but that would be an overkill if the user does not use the app and it keeps refreshing the token.

Is there any other way that when the user returns, the token Is refreshed upon opening the app?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Arif
  • 377
  • 2
  • 5
  • 21
  • 3
    While Firebase's ID tokens are only valid for an house, the Firebase SDKs automatically refresh them before they expire and you should in most use not ever experience an expired token. It's really hard to say why that isn't the case for you from the description though. Can you edit your question to show the [minimal code + steps that any of us can take/run to reproduce the problem](http://stackoverflow.com/help/mcve)? – Frank van Puffelen Apr 02 '22 at 21:37
  • does it also automatically refresh it if the user closes the app and opens it again after few days? – Arif Apr 04 '22 at 08:53
  • Yeah, there is no timeout. Since it sounds like that is not happening for you, the best path forward is if you can show us how ti reproduce the problem. – Frank van Puffelen Apr 04 '22 at 14:35
  • Recently I've started to see the same issue when using Play Integrity with app check on Firestore resources. Vanilla implementation, just Firestore, auth and plat integrity, at least once every day or two the refresh fails causing the calls to the Firestore to fail. – Joao Gavazzi Jul 11 '22 at 18:43

0 Answers0