Skip to content

Commit 23f1643

Browse files
Added new hook useAuthUrl (#73)
* Added new hook useAuthUrl * Bump version & export
1 parent 07f8688 commit 23f1643

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "git",
66
"url": "https://github.com/PropelAuth/react"
77
},
8-
"version": "2.0.26",
8+
"version": "2.0.27",
99
"license": "MIT",
1010
"keywords": [
1111
"auth",

src/AuthContext.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export interface InternalAuthState {
3737
getOrgPageUrl(orgId?: string, options?: RedirectToOrgPageOptions): string
3838
getCreateOrgPageUrl(options?: RedirectToCreateOrgOptions): string
3939
getSetupSAMLPageUrl(orgId: string, options?: RedirectToSetupSAMLPageOptions): string
40+
41+
authUrl: string
42+
4043
tokens: Tokens
4144
refreshAuthInfo: () => Promise<void>
4245
defaultDisplayWhileLoading?: React.ReactElement
@@ -201,6 +204,7 @@ export const AuthProvider = (props: AuthProviderProps) => {
201204
getOrgPageUrl,
202205
getCreateOrgPageUrl,
203206
getSetupSAMLPageUrl,
207+
authUrl,
204208
refreshAuthInfo,
205209
tokens: {
206210
getAccessTokenForOrg,

src/AuthContextForTesting.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type AuthProviderForTestingProps = {
2626
loading?: boolean
2727
userInformation?: UserInformationForTesting
2828
activeOrgFn?: () => string | null
29+
authUrl?: string
2930
children?: React.ReactNode
3031
}
3132

@@ -37,6 +38,7 @@ export const AuthProviderForTesting = ({
3738
loading,
3839
userInformation,
3940
activeOrgFn,
41+
authUrl,
4042
children,
4143
}: AuthProviderForTestingProps) => {
4244
const authInfo = getAuthInfoForTesting(userInformation)
@@ -70,6 +72,7 @@ export const AuthProviderForTesting = ({
7072
getOrgPageUrl: () => "",
7173
getCreateOrgPageUrl: () => "",
7274
getSetupSAMLPageUrl: () => "",
75+
authUrl: authUrl ?? "https://auth.example.com",
7376
activeOrgFn: activeOrgFnWithDefault,
7477
refreshAuthInfo: () => Promise.resolve(),
7578
tokens: {

src/hooks/useAuthUrl.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useContext } from "react"
2+
import { AuthContext } from "../AuthContext"
3+
4+
export function useAuthUrl() {
5+
const context = useContext(AuthContext)
6+
if (context === undefined) {
7+
throw new Error("useAuthUrl must be used within an AuthProvider or RequiredAuthProvider")
8+
}
9+
const { authUrl } = context
10+
return authUrl
11+
}

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type {
3131
} from "./hooks/additionalHooks"
3232
export { loadOrgSelectionFromLocalStorage, saveOrgSelectionToLocalStorage, useActiveOrg } from "./hooks/useActiveOrg"
3333
export { useAuthInfo } from "./hooks/useAuthInfo"
34+
export { useAuthUrl } from "./hooks/useAuthUrl"
3435
export { useHostedPageUrls } from "./hooks/useHostedPageUrls"
3536
export { useLogoutFunction } from "./hooks/useLogoutFunction"
3637
export { RedirectToLogin, RedirectToSignup, useRedirectFunctions } from "./hooks/useRedirectFunctions"

0 commit comments

Comments
 (0)