@@ -28,7 +28,7 @@ import {
2828 deprecateRedirectUri ,
2929} from './utils' ;
3030import { reducer } from './reducer' ;
31- import { initialAuthState } from './auth-state' ;
31+ import { initialAuthState , type AuthState } from './auth-state' ;
3232
3333/**
3434 * The state of the application before the user was redirected to the login page.
@@ -41,7 +41,7 @@ export type AppState = {
4141/**
4242 * The main configuration to instantiate the `Auth0Provider`.
4343 */
44- export interface Auth0ProviderOptions extends Auth0ClientOptions {
44+ export interface Auth0ProviderOptions < TUser extends User = User > extends Auth0ClientOptions {
4545 /**
4646 * The child nodes your Provider has wrapped
4747 */
@@ -51,7 +51,7 @@ export interface Auth0ProviderOptions extends Auth0ClientOptions {
5151 * It uses `window.history` but you might want to overwrite this if you are using a custom router, like `react-router-dom`
5252 * See the EXAMPLES.md for more info.
5353 */
54- onRedirectCallback ?: ( appState ?: AppState , user ?: User ) => void ;
54+ onRedirectCallback ?: ( appState ?: AppState , user ?: TUser ) => void ;
5555 /**
5656 * By default, if the page url has code/state params, the SDK will treat them as Auth0's and attempt to exchange the
5757 * code for a token. In some cases the code might be for something else (another OAuth SDK perhaps). In these
@@ -83,7 +83,7 @@ export interface Auth0ProviderOptions extends Auth0ClientOptions {
8383 *
8484 * For a sample on using multiple Auth0Providers review the [React Account Linking Sample](https://github.com/auth0-samples/auth0-link-accounts-sample/tree/react-variant)
8585 */
86- context ?: React . Context < Auth0ContextInterface > ;
86+ context ?: React . Context < Auth0ContextInterface < TUser > > ;
8787}
8888
8989/**
@@ -132,7 +132,7 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
132132 *
133133 * Provides the Auth0Context to its child components.
134134 */
135- const Auth0Provider = ( opts : Auth0ProviderOptions ) => {
135+ const Auth0Provider = < TUser extends User = User > ( opts : Auth0ProviderOptions < TUser > ) => {
136136 const {
137137 children,
138138 skipRedirectCallback,
@@ -143,7 +143,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
143143 const [ client ] = useState (
144144 ( ) => new Auth0Client ( toAuth0ClientOptions ( clientOpts ) )
145145 ) ;
146- const [ state , dispatch ] = useReducer ( reducer , initialAuthState ) ;
146+ const [ state , dispatch ] = useReducer ( reducer < TUser > , initialAuthState as AuthState < TUser > ) ;
147147 const didInitialise = useRef ( false ) ;
148148
149149 const handleError = useCallback ( ( error : Error ) => {
@@ -158,7 +158,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
158158 didInitialise . current = true ;
159159 ( async ( ) : Promise < void > => {
160160 try {
161- let user : User | undefined ;
161+ let user : TUser | undefined ;
162162 if ( hasAuthParams ( ) && ! skipRedirectCallback ) {
163163 const { appState } = await client . handleRedirectCallback ( ) ;
164164 user = await client . getUser ( ) ;
@@ -272,7 +272,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
272272 [ client ]
273273 ) ;
274274
275- const contextValue = useMemo < Auth0ContextInterface < User > > ( ( ) => {
275+ const contextValue = useMemo < Auth0ContextInterface < TUser > > ( ( ) => {
276276 return {
277277 ...state ,
278278 getAccessTokenSilently,
0 commit comments