samuelgozi / firebase-auth-lite

A lightweight firebase auth alternative for the browser
MIT License
119 stars 19 forks source link

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

Open sallaben opened 3 years ago

sallaben commented 3 years ago

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 commented 3 years ago

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

samuelgozi commented 3 years ago

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.

sallaben commented 3 years ago

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.

samuelgozi commented 3 years ago

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.

sallaben commented 3 years ago

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.

samuelgozi commented 3 years ago

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