Skip to content

Commit d2c46ed

Browse files
committed
Call onRedirectCallback also when logging in fails
1 parent 1644bb5 commit d2c46ed

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

__tests__/auth-provider.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('Auth0Provider', () => {
225225
});
226226
});
227227

228-
it('should handle redirect callback errors', async () => {
228+
it('should handle redirect callback errors and clear the url', async () => {
229229
window.history.pushState(
230230
{},
231231
document.title,
@@ -244,6 +244,7 @@ describe('Auth0Provider', () => {
244244
expect(() => {
245245
throw result.current.error;
246246
}).toThrowError('__test_error__');
247+
expect(window.location.href).toBe('https://www.example.com/');
247248
});
248249
});
249250

src/auth0-provider.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,21 @@ const Auth0Provider = (opts: Auth0ProviderOptions) => {
157157
}
158158
didInitialise.current = true;
159159
(async (): Promise<void> => {
160+
let appState: AppState | undefined
161+
let user: User | undefined;
160162
try {
161-
let user: User | undefined;
162163
if (hasAuthParams() && !skipRedirectCallback) {
163-
const { appState } = await client.handleRedirectCallback();
164+
appState = (await client.handleRedirectCallback()).appState;
164165
user = await client.getUser();
165-
onRedirectCallback(appState, user);
166166
} else {
167167
await client.checkSession();
168168
user = await client.getUser();
169169
}
170170
dispatch({ type: 'INITIALISED', user });
171171
} catch (error) {
172172
handleError(loginError(error));
173+
} finally {
174+
onRedirectCallback(appState, user);
173175
}
174176
})();
175177
}, [client, onRedirectCallback, skipRedirectCallback, handleError]);

0 commit comments

Comments
 (0)