Skip to content

Commit

Permalink
Call onRedirectCallback also when logging in fails
Browse files Browse the repository at this point in the history
  • Loading branch information
thesauri committed Mar 1, 2025
1 parent 1644bb5 commit 5b7c460
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion __tests__/auth-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('Auth0Provider', () => {
});
});

it('should handle redirect callback errors', async () => {
it('should handle redirect callback errors and clear the url', async () => {
window.history.pushState(
{},
document.title,
Expand All @@ -244,6 +244,7 @@ describe('Auth0Provider', () => {
expect(() => {
throw result.current.error;
}).toThrowError('__test_error__');
expect(window.location.href).toBe('https://www.example.com/');
});
});

Expand Down
8 changes: 5 additions & 3 deletions src/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,21 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
}
didInitialise.current = true;
(async (): Promise<void> => {
let appState: AppState | undefined
let user: User | undefined;
try {
let user: User | undefined;
if (hasAuthParams() && !skipRedirectCallback) {
const { appState } = await client.handleRedirectCallback();
appState = (await client.handleRedirectCallback()).appState;
user = await client.getUser();
onRedirectCallback(appState, user);
} else {
await client.checkSession();
user = await client.getUser();
}
dispatch({ type: 'INITIALISED', user });
} catch (error) {
handleError(loginError(error));
} finally {
onRedirectCallback(appState, user);
}
})();
}, [client, onRedirectCallback, skipRedirectCallback, handleError]);
Expand Down

0 comments on commit 5b7c460

Please sign in to comment.