Skip to content

Commit bea7372

Browse files
committed
Add skipInitialFetch option
1 parent 432ee89 commit bea7372

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/AuthContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type AuthProviderProps = {
5656
getActiveOrgFn?: () => string | null
5757
children?: React.ReactNode
5858
minSecondsBeforeRefresh?: number
59+
skipInitialFetch?: boolean
5960
}
6061

6162
export interface RequiredAuthProviderProps
@@ -105,6 +106,7 @@ export const AuthProvider = (props: AuthProviderProps) => {
105106
const {
106107
authUrl,
107108
minSecondsBeforeRefresh,
109+
skipInitialFetch,
108110
getActiveOrgFn: deprecatedGetActiveOrgFn,
109111
children,
110112
defaultDisplayWhileLoading,
@@ -114,6 +116,7 @@ export const AuthProvider = (props: AuthProviderProps) => {
114116
const { clientRef, accessTokenChangeCounter } = useClientRef({
115117
authUrl,
116118
minSecondsBeforeRefresh,
119+
skipInitialFetch
117120
})
118121

119122
// Refresh the token when the user has logged in or out

src/useClientRef.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ type ClientRef = {
99
interface UseClientRefProps {
1010
authUrl: string
1111
minSecondsBeforeRefresh?: number
12+
skipInitialFetch?: boolean
1213
}
1314

1415
export const useClientRef = (props: UseClientRefProps) => {
1516
const [accessTokenChangeCounter, setAccessTokenChangeCounter] = useState(0)
16-
const { authUrl, minSecondsBeforeRefresh } = props
17+
const { authUrl, minSecondsBeforeRefresh, skipInitialFetch } = props
1718

1819
// Use a ref to store the client so that it doesn't get recreated on every render
1920
const clientRef = useRef<ClientRef | null>(null)
2021
if (clientRef.current === null) {
21-
const client = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh })
22+
const client = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch })
2223
client.addAccessTokenChangeObserver(() => setAccessTokenChangeCounter((x) => x + 1))
2324
clientRef.current = { authUrl, client }
2425
}
@@ -32,7 +33,7 @@ export const useClientRef = (props: UseClientRefProps) => {
3233
} else {
3334
clientRef.current.client.destroy()
3435

35-
const newClient = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh })
36+
const newClient = createClient({ authUrl, enableBackgroundTokenRefresh: true, minSecondsBeforeRefresh, skipInitialFetch })
3637
newClient.addAccessTokenChangeObserver(() => setAccessTokenChangeCounter((x) => x + 1))
3738
clientRef.current = { authUrl, client: newClient }
3839
}

0 commit comments

Comments
 (0)