When shall we set FirebaseUser.getToken(Boolean forcerefresh) to true?

android, firebase, firebase-authentication

Solution

In general, set forceRefresh to false. That is the recommended behavior. However, that depends on what your are doing. You may want to ensure your token is up to date at all times and available synchronously. To do so you have to refresh a couple of minutes before the the token expires. If you call getToken(false), you will get back the cached token which is about to expire which is not desired. In that case, you force a refresh and update the token. By doing so, you ensure you have an unexpired token at all times synchronously.

Problem

My Firebase client app communicates with a custom back-end server, so I need to send the `ID` Token with every HTTPS request to my server. From the reference, ``` Should only be set to true if the token is invalidated out of band ``` - When shall I set the `forcerefresh` boolean to `true`? - Is it okay to get the token(using `forcerefresh` as false) during every HTTPS request to my custom server. (As it returns as a task, Shall i store it in my local cache, so that i don't have to add any task listener and can process the request in the same thread ) EDIT: Now google provides new api which will refresh the token automatically if it is expired. ``` getIdToken(forceRefresh) returns firebase.Promise containing string ``` From the Google Docs Returns the current token if it has not expired, otherwise this will refresh the token and return a new one

Original source