Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/PropelAuth/react"
},
"version": "2.0.24",
"version": "2.0.25",
"license": "MIT",
"keywords": [
"auth",
Expand Down
25 changes: 18 additions & 7 deletions src/AuthContextForTesting.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AccessHelper,
AccessHelperWithOrg,
AccessTokenForActiveOrg,
AuthenticationInfo,
OrgHelper,
OrgIdToOrgMemberInfo,
Expand All @@ -10,14 +11,15 @@ import {
User,
UserClass,
} from "@propelauth/javascript"
import React from "react"
import React, { useCallback } from "react"
import { AuthContext, InternalAuthState } from "./AuthContext"

// User information that we will hard code within the AuthProvider
export type UserInformationForTesting = {
user: User
orgMemberInfos: OrgMemberInfo[]
accessToken?: string
getAccessTokenForOrg?: (orgId: string) => Promise<AccessTokenForActiveOrg>
}

export type AuthProviderForTestingProps = {
Expand All @@ -39,6 +41,19 @@ export const AuthProviderForTesting = ({
}: AuthProviderForTestingProps) => {
const authInfo = getAuthInfoForTesting(userInformation)
const activeOrgFnWithDefault = activeOrgFn ? activeOrgFn : () => null
const getAccessTokenForOrg = useCallback(
(orgId: string) => {
if (userInformation?.getAccessTokenForOrg) {
return userInformation.getAccessTokenForOrg(orgId)
}
return Promise.resolve({
error: undefined,
accessToken: "ACCESS_TOKEN",
})
},
[userInformation?.getAccessTokenForOrg]
)

const contextValue: InternalAuthState = {
loading: !!loading,
authInfo,
Expand All @@ -58,12 +73,8 @@ export const AuthProviderForTesting = ({
activeOrgFn: activeOrgFnWithDefault,
refreshAuthInfo: () => Promise.resolve(),
tokens: {
getAccessTokenForOrg: () =>
Promise.resolve({
error: undefined,
accessToken: "ACCESS_TOKEN",
}),
getAccessToken: () => Promise.resolve("ACCESS_TOKEN"),
getAccessTokenForOrg: getAccessTokenForOrg,
getAccessToken: () => Promise.resolve(userInformation?.accessToken ?? "ACCESS_TOKEN"),
},
}

Expand Down