samuelgozi / firebase-auth-lite

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

Equivalent method to Firebase's `getIdToken()`? #52

Closed harvitronix closed 4 years ago

harvitronix commented 4 years ago

First of all, thank you so much for your work on this. It's a life safer.

I need to programmatically get the user's ID token, refreshed if it's expired. In the official SDK, I would use const token = await user.getIdToken(), and know that I would have a valid token. (For context, this is happening in a background fetch() call, so there's no re-render or other action happening that is triggering emit() before this call is made, so the token could be over an hour old, therefore expired.)

I tried calling the refreshIdToken() method directly when the fetch is made, expecting it to update the state and then trigger the listener, which would update token manager's ID token. But it doesn't seem to update the token when I call it directly. If I refresh the page in my app, it refreshes the token as expected.

Any ideas? Much appreciated. 🙏

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.60. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

samuelgozi commented 4 years ago

Sorry for the late response. If you are using fetch or a fetch polyfill you can call: auth.authorizedRequest with the same arguments you would use in fetch. This method is a wrapper around fetch that also adds the authorization header to each request.

If this doesn't seem to work with your workflow, let me know and I'll work something out.

harvitronix commented 4 years ago

@samuelgozi This worked great! Not sure how I missed that when browsing the code. Thank you. 👍