Skip to content

Commit

Permalink
Merge 011f5aa into ed0d23c
Browse files Browse the repository at this point in the history
  • Loading branch information
aecorredor committed Jan 30, 2024
2 parents ed0d23c + 011f5aa commit 1a98e3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useOAuthFlow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test('allows for providing auth config as a function', () => {
});

expect(authConfigFn).toHaveBeenCalledTimes(1);
expect(authConfigFn).toHaveBeenCalledWith(authResult);
expect(authConfigFn).toHaveBeenCalledWith(authResult.accessToken);
expect(result.current.authConfig).toEqual({
...authConfig,
additionalParameters,
Expand Down
20 changes: 12 additions & 8 deletions src/hooks/useOAuthFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export interface LogoutParams {
* OAuth flows.
*
* While typically not needed, this function is invoked with the current
* auth result to be able to provide a dynamic auth configuration.
* access token to be able to provide a dynamic auth configuration.
*
* @example
* <RootProviders
* authConfig={(currentAuthResult) => {
* authConfig={(currentAccessToken) => {
* if (...) {
* return {
* ...config,
Expand All @@ -53,9 +53,7 @@ export interface LogoutParams {
* }}
* />
*/
export type AuthConfigGetter = (
currentAuthResult?: AuthResult,
) => AuthConfiguration;
export type AuthConfigGetter = (accessToken?: string) => AuthConfiguration;

const OAuthContext = createContext<OAuthConfig>({
login: (_) => Promise.reject(),
Expand All @@ -82,9 +80,9 @@ export const OAuthContextProvider = ({
const authConfig = useMemo(
() =>
typeof authConfigOrGetter === 'function'
? authConfigOrGetter(authResult)
? authConfigOrGetter(authResult?.accessToken)
: authConfigOrGetter,
[authConfigOrGetter, authResult],
[authConfigOrGetter, authResult?.accessToken],
);

// PKCE is required
Expand Down Expand Up @@ -143,7 +141,13 @@ export const OAuthContextProvider = ({
onFail?.(error);
}
},
[queryClient, isLoggedIn, authResult, clearAuthResult, authConfig],
[
queryClient,
isLoggedIn,
authResult?.refreshToken,
clearAuthResult,
authConfig,
],
);

const login = useCallback(
Expand Down

0 comments on commit 1a98e3d

Please sign in to comment.