Open sallaben opened 3 years ago
possibly related: #52, I will try this approach but I am still wondering about my original question
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.
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.
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.
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.
The changes should be up in NPM. If not, please let me know.
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
.