From ac52528f41855a92287b02e542fc989584af19d7 Mon Sep 17 00:00:00 2001 From: Andrew Israel Date: Mon, 30 Dec 2024 13:54:37 -0800 Subject: [PATCH 1/2] Added new hook useAuthUrl --- src/AuthContext.tsx | 4 ++++ src/AuthContextForTesting.tsx | 3 +++ src/hooks/useAuthUrl.tsx | 11 +++++++++++ 3 files changed, 18 insertions(+) create mode 100644 src/hooks/useAuthUrl.tsx diff --git a/src/AuthContext.tsx b/src/AuthContext.tsx index fddda32..5f58099 100644 --- a/src/AuthContext.tsx +++ b/src/AuthContext.tsx @@ -37,6 +37,9 @@ export interface InternalAuthState { getOrgPageUrl(orgId?: string, options?: RedirectToOrgPageOptions): string getCreateOrgPageUrl(options?: RedirectToCreateOrgOptions): string getSetupSAMLPageUrl(orgId: string, options?: RedirectToSetupSAMLPageOptions): string + + authUrl: string + tokens: Tokens refreshAuthInfo: () => Promise defaultDisplayWhileLoading?: React.ReactElement @@ -201,6 +204,7 @@ export const AuthProvider = (props: AuthProviderProps) => { getOrgPageUrl, getCreateOrgPageUrl, getSetupSAMLPageUrl, + authUrl, refreshAuthInfo, tokens: { getAccessTokenForOrg, diff --git a/src/AuthContextForTesting.tsx b/src/AuthContextForTesting.tsx index 1324f2c..980e132 100644 --- a/src/AuthContextForTesting.tsx +++ b/src/AuthContextForTesting.tsx @@ -26,6 +26,7 @@ export type AuthProviderForTestingProps = { loading?: boolean userInformation?: UserInformationForTesting activeOrgFn?: () => string | null + authUrl?: string children?: React.ReactNode } @@ -37,6 +38,7 @@ export const AuthProviderForTesting = ({ loading, userInformation, activeOrgFn, + authUrl, children, }: AuthProviderForTestingProps) => { const authInfo = getAuthInfoForTesting(userInformation) @@ -70,6 +72,7 @@ export const AuthProviderForTesting = ({ getOrgPageUrl: () => "", getCreateOrgPageUrl: () => "", getSetupSAMLPageUrl: () => "", + authUrl: authUrl ?? "https://auth.example.com", activeOrgFn: activeOrgFnWithDefault, refreshAuthInfo: () => Promise.resolve(), tokens: { diff --git a/src/hooks/useAuthUrl.tsx b/src/hooks/useAuthUrl.tsx new file mode 100644 index 0000000..19d2509 --- /dev/null +++ b/src/hooks/useAuthUrl.tsx @@ -0,0 +1,11 @@ +import { useContext } from "react" +import { AuthContext } from "../AuthContext" + +export function useAuthUrl() { + const context = useContext(AuthContext) + if (context === undefined) { + throw new Error("useAuthUrl must be used within an AuthProvider or RequiredAuthProvider") + } + const { authUrl } = context + return authUrl +} From 820a0ebb9bc3dea8e689d602c07372aec68639a8 Mon Sep 17 00:00:00 2001 From: Andrew Israel Date: Mon, 30 Dec 2024 13:59:32 -0800 Subject: [PATCH 2/2] Bump version & export --- package.json | 2 +- src/index.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e03d52..65cf04b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "git", "url": "https://github.com/PropelAuth/react" }, - "version": "2.0.26", + "version": "2.0.27", "license": "MIT", "keywords": [ "auth", diff --git a/src/index.tsx b/src/index.tsx index 73e24f4..b903d39 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -31,6 +31,7 @@ export type { } from "./hooks/additionalHooks" export { loadOrgSelectionFromLocalStorage, saveOrgSelectionToLocalStorage, useActiveOrg } from "./hooks/useActiveOrg" export { useAuthInfo } from "./hooks/useAuthInfo" +export { useAuthUrl } from "./hooks/useAuthUrl" export { useHostedPageUrls } from "./hooks/useHostedPageUrls" export { useLogoutFunction } from "./hooks/useLogoutFunction" export { RedirectToLogin, RedirectToSignup, useRedirectFunctions } from "./hooks/useRedirectFunctions"