Skip to content

Commit f29fdaa

Browse files
authored
Merge pull request #3364 from RedisInsight/fe/bugfix/RI-5733
#RI-5733 - fix logout on switch account
2 parents 9dc0b86 + 0d78a00 commit f29fdaa

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

redisinsight/ui/src/constants/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ export const CLOUD_AUTH_API_ENDPOINTS = [
164164
ApiEndpoints.CLOUD_ME,
165165
ApiEndpoints.CLOUD_ME_JOBS,
166166
ApiEndpoints.CLOUD_ME_ACCOUNTS,
167-
ApiEndpoints.CLOUD_CURRENT,
168167
ApiEndpoints.CLOUD_SUBSCRIPTION_PLANS,
169168
ApiEndpoints.CLOUD_ME_AUTODISCOVERY_ACCOUNT,
170169
ApiEndpoints.CLOUD_ME_AUTODISCOVERY_SUBSCRIPTIONS,

redisinsight/ui/src/slices/oauth/cloud.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AxiosError } from 'axios'
33
import { remove } from 'lodash'
44
import { apiService, localStorageService } from 'uiSrc/services'
55
import { ApiEndpoints, BrowserStorageItem, Pages } from 'uiSrc/constants'
6-
import { getApiErrorMessage, getAxiosError, isStatusSuccessful, Nullable } from 'uiSrc/utils'
6+
import { getApiErrorCode, getApiErrorMessage, getAxiosError, isStatusSuccessful, Nullable } from 'uiSrc/utils'
77

88
import { CloudJobName, CloudJobStatus } from 'uiSrc/electron/constants'
99
import {
@@ -34,6 +34,7 @@ import {
3434
removeInfiniteNotification
3535
} from '../app/notifications'
3636
import { checkConnectToInstanceAction, setConnectedInstanceId } from '../instances/instances'
37+
import ApiStatusCode from '../../constants/apiStatusCode'
3738

3839
export const initialState: StateAppOAuth = {
3940
loading: false,
@@ -415,6 +416,11 @@ export function activateAccount(
415416
} catch (error) {
416417
const err = getAxiosError(error as EnhancedAxiosError)
417418
const errorMessage = getApiErrorMessage(error as AxiosError)
419+
const errorCode = getApiErrorCode(error as AxiosError)
420+
421+
if (errorCode === ApiStatusCode.Unauthorized) {
422+
dispatch<any>(logoutUserAction())
423+
}
418424

419425
dispatch(addErrorNotification(err))
420426
dispatch(getUserInfoFailure(errorMessage))

redisinsight/ui/src/utils/apiResponse.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const getAxiosError = (error: EnhancedAxiosError): AxiosError => {
1212
return error
1313
}
1414

15+
export const getApiErrorCode = (error: AxiosError) => error?.response?.status
16+
1517
export function getApiErrorMessage(error: AxiosError): string {
1618
const errorMessage = error?.response?.data?.message
1719
if (!error || !error.response) {

redisinsight/ui/src/utils/tests/apiResponse.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { AxiosError } from 'axios'
2-
import { DEFAULT_ERROR_MESSAGE, getApiErrorMessage, getAxiosError, parseCloudOAuthError } from 'uiSrc/utils'
2+
import {
3+
DEFAULT_ERROR_MESSAGE,
4+
getApiErrorCode,
5+
getApiErrorMessage,
6+
getAxiosError,
7+
parseCloudOAuthError
8+
} from 'uiSrc/utils'
39
import { EnhancedAxiosError } from 'uiSrc/slices/interfaces'
410

511
const error = { response: { data: { message: 'error' } } } as AxiosError
612
const errors = { response: { data: { message: ['error1', 'error2'] } } } as AxiosError
713

8-
const customError1: EnhancedAxiosError = { response: { data: { message: 'error' } } }
9-
const customError2: EnhancedAxiosError = { response: { data: { message: 'error', errorCode: 11_002 } } }
10-
const customError3: EnhancedAxiosError = { response: { data: { message: 'error', error: 'UnexpectedError' } } }
14+
const customError1: EnhancedAxiosError = { response: { data: { message: 'error' }, status: 500 } }
15+
const customError2: EnhancedAxiosError = { response: { data: { message: 'error', errorCode: 11_002 }, status: 402 } }
16+
const customError3: EnhancedAxiosError = { response: { data: { message: 'error', error: 'UnexpectedError' }, status: 503 } }
1117

1218
describe('getAxiosError', () => {
1319
it('should return proper error', () => {
@@ -24,3 +30,11 @@ describe('getApiErrorMessage', () => {
2430
expect(getApiErrorMessage(errors)).toEqual('error1')
2531
})
2632
})
33+
34+
describe('getAxiosError', () => {
35+
it('should return proper error code', () => {
36+
expect(getApiErrorCode(customError1)).toEqual(500)
37+
expect(getApiErrorCode(customError2)).toEqual(402)
38+
expect(getApiErrorCode(customError3)).toEqual(503)
39+
})
40+
})

0 commit comments

Comments
 (0)