Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor double-fetch for token changes #212

Merged
merged 1 commit into from
Apr 3, 2024
Merged

Conversation

8cw
Copy link
Contributor

@8cw 8cw commented Apr 3, 2024

Previously we would perform a getIdTokenResult(), followed by a getIdToken() call. This is two API calls to Firebase, and can be simplfied by using the token property from the resutl of getIdTokenResult().

Also updates the onIdTokenChanged flow to handle errors more gracefully, by returning early if we are unable to retrieve the token details (rather than setting null data to memory.

Observing the source of getIdTokenResult at
https://github.com/firebase/firebase-js-sdk/blob/6d31930b3abe1588ae81a5c14b59cd386fddc718/packages/auth/src/core/user/id_token_result.ts#L55-L88 it is evident that it calls getIdToken internally.

See https://github.com/firebase/firebase-js-sdk/blob/6d31930b3abe1588ae81a5c14b59cd386fddc718/packages/auth/src/core/user/user_impl.ts#L102-L116 for the original getIdToken source.

Previously we would perform a `getIdTokenResult()`, followed by a
`getIdToken()` call. This is two API calls to Firebase, and can be
simplfied by using the `token` property from the resutl of
`getIdTokenResult()`.

Also updates the `onIdTokenChanged` flow to handle errors more
gracefully, by `return`ing early if we are unable to retrieve the token
details (rather than setting `null` data to memory.

Observing the source of `getIdTokenResult` at
https://github.com/firebase/firebase-js-sdk/blob/6d31930b3abe1588ae81a5c14b59cd386fddc718/packages/auth/src/core/user/id_token_result.ts#L55-L88
it is evident that it calls `getIdToken` internally.
@8cw 8cw added the frontend relating to code in the /client directory label Apr 3, 2024
@8cw 8cw requested a review from choden-dev April 3, 2024 05:28
@8cw 8cw self-assigned this Apr 3, 2024
Copy link

github-actions bot commented Apr 3, 2024

Visit the preview URL for this PR (updated for commit 1db3ebd):

https://uasc-ceebc--pr212-refactor-auth-token-k6dkefud.web.app

(expires Wed, 10 Apr 2024 05:30:42 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 36296ceaed1d43e92e7d5e81a72a7bd987560bfa

@8cw 8cw merged commit 38b9ec3 into master Apr 3, 2024
8 checks passed
@8cw 8cw deleted the refactor-auth-token-changes branch April 3, 2024 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend relating to code in the /client directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants