Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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