44 * @internal
55 */
66
7- import type { FetcherSupplier , SpaAuthConfig } from '../auth/auth-types' ;
7+ import type { FetcherAuthParams , FetcherSupplier , SpaAuthConfig } from '../auth/auth-types' ;
88
99import { ContentType , HeaderName } from './http-constants' ;
1010
@@ -18,16 +18,22 @@ export const AUTH0_SCOPE_HEADER = HeaderName.Auth0Scope;
1818 * @internal
1919 */
2020export function createProxyFetcher (
21- customFetcher ?: ( url : string , init ?: RequestInit ) => Promise < Response > ,
21+ customFetcher ?: (
22+ url : string ,
23+ init ?: RequestInit ,
24+ authParams ?: FetcherAuthParams ,
25+ ) => Promise < Response > ,
2226) : FetcherSupplier {
23- const fetchFn = customFetcher ?? fetch ;
2427 return async ( url , init , authParams ) => {
2528 const headers = new Headers ( init ?. headers ) ;
2629 headers . set ( HeaderName . ContentType , ContentType . JSON ) ;
2730 if ( authParams ?. scope ?. length ) {
2831 headers . set ( HeaderName . Auth0Scope , authParams . scope . join ( ' ' ) ) ;
2932 }
30- return fetchFn ( url , { ...init , headers } ) ;
33+ if ( customFetcher ) {
34+ return customFetcher ( url , { ...init , headers } , authParams ) ;
35+ }
36+ return fetch ( url , { ...init , headers } ) ;
3137 } ;
3238}
3339
0 commit comments