firebase-auth-lite icon indicating copy to clipboard operation
firebase-auth-lite copied to clipboard

feature request: A way to force token update when it becomes expired

Open sallaben opened this issue 4 years ago • 6 comments

Hello! I am happy your solution is so much smaller. Do you know if there is a way to update the user object when the token expires? to run when expiry date < new Date()

I see a refresh token in user.tokenmanager, but not sure which method to call with that token, or if there's a parameterless method included with the firebase-auth-lite import.

fetchProfile doesn't seem to update the token, but maybe I need to await a svelte tick.

sallaben avatar Dec 24 '20 14:12 sallaben

possibly related: #52, I will try this approach but I am still wondering about my original question

sallaben avatar Dec 24 '20 15:12 sallaben

Hi and thank you! The library automatically refreshes tokens for you when needed if you use the auth.authorizedRequest method. You can learn more about how it works here: https://github.com/samuelgozi/firebase-auth-lite/wiki/API-Reference#authorizedrequestresource-init

The gist of it is that auth.authorizedRequest should replace fetch for all requests that require authentication. It has the same API as fetch, and actually, the only difference is that it adds the authorization header.

Please let me know if you have more questions.

samuelgozi avatar Dec 24 '20 17:12 samuelgozi

The problem with authorizedRequest, though it is quite useful if I were using fetch, is that I would like to use axios instead of fetch API. How does authorizedRequest ensure it has an updated token? Maybe I could replicate that logic.

sallaben avatar Dec 24 '20 17:12 sallaben

Sorry for the delay in responses. Please read this PR: https://github.com/samuelgozi/firebase-auth-lite/pull/54 And let me know if it solves your problem.

samuelgozi avatar Jan 01 '21 09:01 samuelgozi

thanks @samuelgozi and @ocruzv -- this is exactly the functionality I was hoping for!

Do we have an estimate on when the next npm release will happen? I'm happy to contribute code review or help in any other way if you have outstanding items to accomplish.

sallaben avatar Jan 01 '21 17:01 sallaben

The changes should be up in NPM. If not, please let me know.

samuelgozi avatar Jan 02 '21 18:01 samuelgozi