11import {
22 AccessHelper ,
33 AccessHelperWithOrg ,
4+ AccessTokenForActiveOrg ,
45 AuthenticationInfo ,
56 OrgHelper ,
67 OrgIdToOrgMemberInfo ,
@@ -10,14 +11,15 @@ import {
1011 User ,
1112 UserClass ,
1213} from "@propelauth/javascript"
13- import React from "react"
14+ import React , { useCallback } from "react"
1415import { AuthContext , InternalAuthState } from "./AuthContext"
1516
1617// User information that we will hard code within the AuthProvider
1718export type UserInformationForTesting = {
1819 user : User
1920 orgMemberInfos : OrgMemberInfo [ ]
2021 accessToken ?: string
22+ getAccessTokenForOrg ?: ( orgId : string ) => Promise < AccessTokenForActiveOrg >
2123}
2224
2325export type AuthProviderForTestingProps = {
@@ -39,6 +41,19 @@ export const AuthProviderForTesting = ({
3941} : AuthProviderForTestingProps ) => {
4042 const authInfo = getAuthInfoForTesting ( userInformation )
4143 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+
4257 const contextValue : InternalAuthState = {
4358 loading : ! ! loading ,
4459 authInfo,
@@ -58,12 +73,8 @@ export const AuthProviderForTesting = ({
5873 activeOrgFn : activeOrgFnWithDefault ,
5974 refreshAuthInfo : ( ) => Promise . resolve ( ) ,
6075 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" ) ,
6778 } ,
6879 }
6980
0 commit comments