You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can use an external library (e.g., jwt-decode) to validate the Firebase token.
So even though we can't get the token from the Firebase SDK synchronously, this barrier will get it asynchronously if the token is undefined.
constFIVE_MINUTES_MS=5*60*1000// Firebase default behavior to fetch new token if 5 minutes leftconstisTokenAlmostExpired=(jwt: string|null)=>{if(!jwt)returntrueconst{ exp }=jwtDecode(jwt)if(!exp)returntruereturnDate.now()+FIVE_MINUTES_MS>exp*1000}exportconstauthBarrier=createBarrier({active: combine($authToken,(token)=>isTokenAlmostExpired(token)),perform: [getTokenMutation],})
In the docs, we have this example:
However, there is no way to check if the token is valid synchronously in Firebase, as getIdToken() always returns a promise.
https://firebase.google.com/docs/reference/js/v8/firebase.User#getidtoken
Maybe active should also accept an effect that returns a boolean?
The text was updated successfully, but these errors were encountered: