From bea7372151a487f40fca0f738a7fc7acd163b797 Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 21 Oct 2025 09:13:14 -0600 Subject: [PATCH 1/4] Add `skipInitialFetch` option --- src/AuthContext.tsx | 3 +++ src/useClientRef.tsx | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/AuthContext.tsx b/src/AuthContext.tsx index 0a8ef77..c736c5f 100644 --- a/src/AuthContext.tsx +++ b/src/AuthContext.tsx @@ -56,6 +56,7 @@ export type AuthProviderProps = { getActiveOrgFn?: () => string | null children?: React.ReactNode minSecondsBeforeRefresh?: number + skipInitialFetch?: boolean } export interface RequiredAuthProviderProps @@ -105,6 +106,7 @@ export const AuthProvider = (props: AuthProviderProps) => { const { authUrl, minSecondsBeforeRefresh, + skipInitialFetch, getActiveOrgFn: deprecatedGetActiveOrgFn, children, defaultDisplayWhileLoading, @@ -114,6 +116,7 @@ export const AuthProvider = (props: AuthProviderProps) => { const { clientRef, accessTokenChangeCounter } = useClientRef({ authUrl, minSecondsBeforeRefresh, + skipInitialFetch }) // Refresh the token when the user has logged in or out diff --git a/src/useClientRef.tsx b/src/useClientRef.tsx index 50ea701..4015d8f 100644 --- a/src/useClientRef.tsx +++ b/src/useClientRef.tsx @@ -9,16 +9,17 @@ type ClientRef = { interface UseClientRefProps { authUrl: string minSecondsBeforeRefresh?: number + skipInitialFetch?: boolean } export const useClientRef = (props: UseClientRefProps) => { const [accessTokenChangeCounter, setAccessTokenChangeCounter] = useState(0) - const { authUrl, minSecondsBeforeRefresh } = props + const { authUrl, minSecondsBeforeRefresh, skipInitialFetch } = props // Use a ref to store the client so that it doesn't get recreated on every render const clientRef = useRef(null) if (clientRef.current === null) { - const client = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh }) + const client = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch }) client.addAccessTokenChangeObserver(() => setAccessTokenChangeCounter((x) => x + 1)) clientRef.current = { authUrl, client } } @@ -32,7 +33,7 @@ export const useClientRef = (props: UseClientRefProps) => { } else { clientRef.current.client.destroy() - const newClient = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh }) + const newClient = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch }) newClient.addAccessTokenChangeObserver(() => setAccessTokenChangeCounter((x) => x + 1)) clientRef.current = { authUrl, client: newClient } } From 243edb248abbaa0d6d8b97dddc92efaa8f96a78e Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 21 Oct 2025 13:41:48 -0600 Subject: [PATCH 2/4] Set skipInitialFetch to true and remove from authprovider --- src/AuthContext.tsx | 3 --- src/useClientRef.tsx | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/AuthContext.tsx b/src/AuthContext.tsx index c736c5f..0a8ef77 100644 --- a/src/AuthContext.tsx +++ b/src/AuthContext.tsx @@ -56,7 +56,6 @@ export type AuthProviderProps = { getActiveOrgFn?: () => string | null children?: React.ReactNode minSecondsBeforeRefresh?: number - skipInitialFetch?: boolean } export interface RequiredAuthProviderProps @@ -106,7 +105,6 @@ export const AuthProvider = (props: AuthProviderProps) => { const { authUrl, minSecondsBeforeRefresh, - skipInitialFetch, getActiveOrgFn: deprecatedGetActiveOrgFn, children, defaultDisplayWhileLoading, @@ -116,7 +114,6 @@ export const AuthProvider = (props: AuthProviderProps) => { const { clientRef, accessTokenChangeCounter } = useClientRef({ authUrl, minSecondsBeforeRefresh, - skipInitialFetch }) // Refresh the token when the user has logged in or out diff --git a/src/useClientRef.tsx b/src/useClientRef.tsx index 4015d8f..aba5652 100644 --- a/src/useClientRef.tsx +++ b/src/useClientRef.tsx @@ -9,17 +9,16 @@ type ClientRef = { interface UseClientRefProps { authUrl: string minSecondsBeforeRefresh?: number - skipInitialFetch?: boolean } export const useClientRef = (props: UseClientRefProps) => { const [accessTokenChangeCounter, setAccessTokenChangeCounter] = useState(0) - const { authUrl, minSecondsBeforeRefresh, skipInitialFetch } = props + const { authUrl, minSecondsBeforeRefresh } = props // Use a ref to store the client so that it doesn't get recreated on every render const clientRef = useRef(null) if (clientRef.current === null) { - const client = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch }) + const client = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch: true }) client.addAccessTokenChangeObserver(() => setAccessTokenChangeCounter((x) => x + 1)) clientRef.current = { authUrl, client } } @@ -33,7 +32,7 @@ export const useClientRef = (props: UseClientRefProps) => { } else { clientRef.current.client.destroy() - const newClient = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch }) + const newClient = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch: true }) newClient.addAccessTokenChangeObserver(() => setAccessTokenChangeCounter((x) => x + 1)) clientRef.current = { authUrl, client: newClient } } From 1d7040ac119c7465890f442e3b860a8959f191cc Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 21 Oct 2025 14:16:08 -0600 Subject: [PATCH 3/4] Bump version and dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9cd9137..aaf111b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "git", "url": "https://github.com/PropelAuth/react" }, - "version": "2.0.31", + "version": "2.0.32", "license": "MIT", "keywords": [ "auth", @@ -13,7 +13,7 @@ "user" ], "dependencies": { - "@propelauth/javascript": "^2.0.22", + "@propelauth/javascript": "^2.0.23", "hoist-non-react-statics": "^3.3.2", "utility-types": "^3.10.0" }, From ab6f10cf0ade1958a5d7986197ca6c533a9b9d62 Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 21 Oct 2025 14:38:48 -0600 Subject: [PATCH 4/4] Update tests with skipInitialFetch --- src/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.test.js b/src/index.test.js index 579fa58..2b56a9e 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -603,7 +603,7 @@ function createMockClient() { const AUTH_URL = "authUrl" function expectCreateClientWasCalledCorrectly() { - expect(createClient).toHaveBeenCalledWith({ authUrl: AUTH_URL, enableBackgroundTokenRefresh: true }) + expect(createClient).toHaveBeenCalledWith({ authUrl: AUTH_URL, enableBackgroundTokenRefresh: true, skipInitialFetch: true }) } function createOrg() {