File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
- import { useAuth0 } from '@auth0/auth0-react' ;
2
- import { useCallback , useEffect } from 'react' ;
1
+ import { Auth0ContextInterface , useAuth0 } from '@auth0/auth0-react' ;
2
+ import { Context , useCallback , useEffect } from 'react' ;
3
3
import { STORAGE_KEY_AUTH_TOKEN , useMonkAppState , useObjectMemo } from '@monkvision/common' ;
4
4
5
5
/**
@@ -12,6 +12,10 @@ export interface UseAuthParams {
12
12
* @default true
13
13
*/
14
14
storeToken ?: boolean ;
15
+ /**
16
+ * Optional custom Auth0 context that will be passed through to the `useAuth0` hook.
17
+ */
18
+ context ?: Context < Auth0ContextInterface > ;
15
19
}
16
20
17
21
/**
@@ -43,7 +47,7 @@ const defaultOptions = {
43
47
*/
44
48
export function useAuth ( params ?: UseAuthParams ) : MonkAuthHandle {
45
49
const options = { ...defaultOptions , ...( params ?? { } ) } ;
46
- const { getAccessTokenWithPopup, logout } = useAuth0 ( ) ;
50
+ const { getAccessTokenWithPopup, logout } = useAuth0 ( params ?. context ) ;
47
51
const { setAuthToken } = useMonkAppState ( ) ;
48
52
49
53
useEffect ( ( ) => {
Original file line number Diff line number Diff line change 1
1
import { STORAGE_KEY_AUTH_TOKEN , useMonkAppState } from '@monkvision/common' ;
2
- import { useAuth0 } from '@auth0/auth0-react' ;
2
+ import { Auth0ContextInterface , useAuth0 } from '@auth0/auth0-react' ;
3
3
import { act , waitFor } from '@testing-library/react' ;
4
4
import { renderHook } from '@testing-library/react-hooks' ;
5
5
import { useAuth } from '../../src' ;
6
+ import { Context } from 'react' ;
6
7
7
8
describe ( 'Authentication hooks' , ( ) => {
8
9
afterEach ( ( ) => {
@@ -116,5 +117,14 @@ describe('Authentication hooks', () => {
116
117
unmount ( ) ;
117
118
( useAuth0 as jest . Mock ) . mockRestore ( ) ;
118
119
} ) ;
120
+
121
+ it ( 'should pass the Auth0 context provided to the useAuth0 hook' , async ( ) => {
122
+ const context = { test : 'hello' } as unknown as Context < Auth0ContextInterface > ;
123
+ const { unmount } = renderHook ( useAuth , { initialProps : { context } } ) ;
124
+
125
+ expect ( useAuth0 ) . toHaveBeenCalledWith ( context ) ;
126
+
127
+ unmount ( ) ;
128
+ } ) ;
119
129
} ) ;
120
130
} ) ;
You can’t perform that action at this time.
0 commit comments