Skip to content

Commit b2dbe17

Browse files
authored
fix(Auth): do not show access error when redirecting to auth (#1803)
1 parent 38c88e5 commit b2dbe17

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

src/components/Errors/PageError/PageError.tsx

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import {isAccessError, isRedirectToAuth} from '../../../utils/response';
34
import type {EmptyStateProps} from '../../EmptyState';
45
import {EmptyState} from '../../EmptyState';
56
import {Illustration} from '../../Illustration';
@@ -15,6 +16,11 @@ interface PageErrorProps extends Omit<EmptyStateProps, 'image' | 'title' | 'desc
1516
}
1617

1718
export function PageError({title, description, error, children, ...restProps}: PageErrorProps) {
19+
if (isRedirectToAuth(error)) {
20+
// Do not show an error, because we redirect to auth anyway.
21+
return null;
22+
}
23+
1824
if (isAccessError(error)) {
1925
return <AccessDenied title={title} description={description} {...restProps} />;
2026
}
@@ -32,12 +38,3 @@ export function PageError({title, description, error, children, ...restProps}: P
3238

3339
return <React.Fragment>{children}</React.Fragment>;
3440
}
35-
36-
export function isAccessError(error: unknown) {
37-
return Boolean(
38-
error &&
39-
typeof error === 'object' &&
40-
'status' in error &&
41-
(error.status === 403 || error.status === 401),
42-
);
43-
}

src/containers/Operations/Operations.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22

33
import {AccessDenied} from '../../components/Errors/403';
4-
import {isAccessError} from '../../components/Errors/PageError/PageError';
54
import {ResponseError} from '../../components/Errors/ResponseError';
65
import {ResizeableDataTable} from '../../components/ResizeableDataTable/ResizeableDataTable';
76
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
87
import {operationsApi} from '../../store/reducers/operations';
98
import {useAutoRefreshInterval} from '../../utils/hooks';
9+
import {isAccessError} from '../../utils/response';
1010

1111
import {OperationsControls} from './OperationsControls';
1212
import {getColumns} from './columns';

src/containers/Tenant/Tenant.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import {Helmet} from 'react-helmet-async';
44
import {StringParam, useQueryParams} from 'use-query-params';
55

6-
import {PageError, isAccessError} from '../../components/Errors/PageError/PageError';
6+
import {PageError} from '../../components/Errors/PageError/PageError';
77
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
88
import SplitPane from '../../components/SplitPane';
99
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
@@ -12,6 +12,7 @@ import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../types/add
1212
import {cn} from '../../utils/cn';
1313
import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants';
1414
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
15+
import {isAccessError} from '../../utils/response';
1516

1617
import ObjectGeneral from './ObjectGeneral/ObjectGeneral';
1718
import {ObjectSummary} from './ObjectSummary/ObjectSummary';

src/services/api/base.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import axiosRetry from 'axios-retry';
44

55
import {backend as BACKEND} from '../../store';
66
import {DEV_ENABLE_TRACING_FOR_ALL_REQUESTS} from '../../utils/constants';
7+
import {isRedirectToAuth} from '../../utils/response';
78
import {settingsManager} from '../settings';
89

910
export type AxiosOptions = {
@@ -63,7 +64,7 @@ export class BaseYdbAPI extends AxiosWrapper {
6364
// OIDC proxy returns 401 response with authUrl in it
6465
// authUrl - external auth service link, after successful auth additional cookies will be appended
6566
// that will allow access to clusters where OIDC proxy is a balancer
66-
if (response && response.status === 401 && response.data?.authUrl) {
67+
if (isRedirectToAuth(response)) {
6768
window.location.assign(response.data.authUrl);
6869
}
6970

src/utils/response.ts

+22
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,25 @@ export function isAxiosError(error: unknown): error is AxiosErrorObject {
2424
error && typeof error === 'object' && 'name' in error && error.name === 'AxiosError',
2525
);
2626
}
27+
28+
export function isAccessError(error: unknown): error is {status: number} {
29+
return Boolean(
30+
error &&
31+
typeof error === 'object' &&
32+
'status' in error &&
33+
(error.status === 403 || error.status === 401),
34+
);
35+
}
36+
37+
export function isRedirectToAuth(error: unknown): error is {status: 401; data: {authUrl: string}} {
38+
return Boolean(
39+
isAccessError(error) &&
40+
error.status === 401 &&
41+
'data' in error &&
42+
error.data &&
43+
typeof error.data === 'object' &&
44+
'authUrl' in error.data &&
45+
error.data.authUrl &&
46+
typeof error.data.authUrl === 'string',
47+
);
48+
}

0 commit comments

Comments
 (0)