Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle auth check cancelation #710

Merged
merged 1 commit into from
Jun 12, 2020
Merged
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
12 changes: 8 additions & 4 deletions webui/react/src/hooks/useAuthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useCallback, useEffect, useState } from 'react';

import Auth from 'contexts/Auth';
import handleError, { ErrorType } from 'ErrorHandler';
import { getCurrentUser } from 'services/api';
import { getCurrentUser, isAuthFailure } from 'services/api';
import { getCookie } from 'utils/browser';

const useAuthCheck = (): (() => void) => {
Expand All @@ -28,17 +28,21 @@ const useAuthCheck = (): (() => void) => {
const user = await getCurrentUser({ cancelToken });
setAuth({ type: Auth.ActionType.Set, value: { isAuthenticated: true, user } });
} catch (e) {
if (axios.isCancel(e)) return;
const isAuthError = isAuthFailure(e);
handleError({
error: e,
isUserTriggered: false,
message: e.message,
publicMessage: 'Unable to verify current user.',
publicSubject: 'GET user failed',
silent: true,
type: ErrorType.Auth,
type: isAuthError ? ErrorType.Auth : ErrorType.Server,
});
setAuth({ type: Auth.ActionType.Reset });
setAuth({ type: Auth.ActionType.MarkChecked });
if (isAuthError) {
setAuth({ type: Auth.ActionType.Reset });
setAuth({ type: Auth.ActionType.MarkChecked });
}
}
};

Expand Down