-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add custom fetch support #64
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
base: main
Are you sure you want to change the base?
Conversation
🚀 Preview deploymentBranch: 📝 Preview URL: https://auth0-universal-components-ent3b7mxy-okta.vercel.app Updated at 2026-01-26T19:49:19.783Z |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64 +/- ##
==========================================
+ Coverage 83.62% 83.64% +0.02%
==========================================
Files 125 125
Lines 10320 10336 +16
Branches 1092 1029 -63
==========================================
+ Hits 8630 8646 +16
Misses 1690 1690 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| const fetcher = customFetch | ||
| ? customFetch | ||
| : async (url: string, init?: RequestInit) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a small thing we should use ?? to avoid this redundant checking pattern
| } else if (auth.domain) { | ||
| const fetcher = async (url: string, init?: RequestInit) => { | ||
| const token = await tokenManagerService.getToken(latestScopes, 'me'); | ||
| const fetcher = customFetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar applies here
| }, | ||
| }); | ||
| }; | ||
| const fetcher = customFetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar changes for this provider
|
|
||
| import type { I18nServiceInterface } from '../i18n'; | ||
|
|
||
| export type CustomFetch = (url: string, init?: RequestInit | undefined) => Promise<Response>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not the same as SPA-JS?
info: RequestInfo | URL,
init?: RequestInit,
Changes
Context
At this moment DPoP is not supported in Components for SPA and we should not be responsible to create or manage this, because we should just relay on the auth SDKs that already manage all the authentication process.
As a first step, we should allow users to pass their own custom fetcher so they can create a fetcher by using the auth SDKs, like
auth0-spa-js(https://github.com/auth0/auth0-spa-js/blob/main/EXAMPLES.md#using-dpop-in-your-own-requests) orauth0-react(https://github.com/auth0/auth0-react/blob/main/EXAMPLES.md#enabling-dpop), and then they can reuse the same fetcher into Universal Components.Next step, not in this PR:
As a second step, we should be able to get the current instance of the fetcher that the
auth0-reactis using from theuseAuth0hook, but the problem is that at this momentuseAuth0only expose thecreateFetcherfunction to allow users to create fetchers, not an instance itself.We are opening conversations about how we can inherit this fetcher directly from
auth0-reactby using theuseAuth0hook, maybeauth0-reactmust instantiate it's own fetcher instead of exposingcreateFetcheror maybe we should just create a new fetcher using this method.PR implementation
This PR adds a new
customFetchproperty intospa-providerandproxy-providerto support custom fetcher for API requests in the different SDK available in CoreClient (MyOrganization and MyAccount).In addition, it updates the documentation to include the new prop.
References
Testing
pnpm run buildexamplesappAuth0ComponentProvideris been used and pass a new function using thecustomFetchprop.examplesappChecklist