1
1
import {
2
2
AccessHelper ,
3
3
AccessHelperWithOrg ,
4
+ AccessTokenForActiveOrg ,
4
5
AuthenticationInfo ,
5
6
OrgHelper ,
6
7
OrgIdToOrgMemberInfo ,
@@ -10,14 +11,15 @@ import {
10
11
User ,
11
12
UserClass ,
12
13
} from "@propelauth/javascript"
13
- import React from "react"
14
+ import React , { useCallback } from "react"
14
15
import { AuthContext , InternalAuthState } from "./AuthContext"
15
16
16
17
// User information that we will hard code within the AuthProvider
17
18
export type UserInformationForTesting = {
18
19
user : User
19
20
orgMemberInfos : OrgMemberInfo [ ]
20
21
accessToken ?: string
22
+ getAccessTokenForOrg ?: ( orgId : string ) => Promise < AccessTokenForActiveOrg >
21
23
}
22
24
23
25
export type AuthProviderForTestingProps = {
@@ -39,6 +41,19 @@ export const AuthProviderForTesting = ({
39
41
} : AuthProviderForTestingProps ) => {
40
42
const authInfo = getAuthInfoForTesting ( userInformation )
41
43
const activeOrgFnWithDefault = activeOrgFn ? activeOrgFn : ( ) => null
44
+ const getAccessTokenForOrg = useCallback (
45
+ ( orgId : string ) => {
46
+ if ( userInformation ?. getAccessTokenForOrg ) {
47
+ return userInformation . getAccessTokenForOrg ( orgId )
48
+ }
49
+ return Promise . resolve ( {
50
+ error : undefined ,
51
+ accessToken : "ACCESS_TOKEN" ,
52
+ } )
53
+ } ,
54
+ [ userInformation ?. getAccessTokenForOrg ]
55
+ )
56
+
42
57
const contextValue : InternalAuthState = {
43
58
loading : ! ! loading ,
44
59
authInfo,
@@ -58,12 +73,8 @@ export const AuthProviderForTesting = ({
58
73
activeOrgFn : activeOrgFnWithDefault ,
59
74
refreshAuthInfo : ( ) => Promise . resolve ( ) ,
60
75
tokens : {
61
- getAccessTokenForOrg : ( ) =>
62
- Promise . resolve ( {
63
- error : undefined ,
64
- accessToken : "ACCESS_TOKEN" ,
65
- } ) ,
66
- getAccessToken : ( ) => Promise . resolve ( "ACCESS_TOKEN" ) ,
76
+ getAccessTokenForOrg : getAccessTokenForOrg ,
77
+ getAccessToken : ( ) => Promise . resolve ( userInformation ?. accessToken ?? "ACCESS_TOKEN" ) ,
67
78
} ,
68
79
}
69
80
0 commit comments