Merge pull request #103 from stephb9959/main

[WIFI-10583] Reacting to more cases where a token might be expired/invalid
This commit is contained in:
Charles Bourque
2022-08-18 10:48:22 +01:00
committed by GitHub
5 changed files with 10 additions and 5 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ucentral-client",
"version": "2.7.0(2)",
"version": "2.7.0(3)",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ucentral-client",
"version": "2.7.0(2)",
"version": "2.7.0(3)",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "2.7.0(2)",
"version": "2.7.0(3)",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",

4
src/constants.js Normal file
View File

@@ -0,0 +1,4 @@
export const AUTH_EXPIRED_TOKEN_CODE = 9;
export const AUTH_INVALID_TOKEN_CODE = 8;
export const LOGOUT_ON_SEC_ERROR_CODES = [AUTH_EXPIRED_TOKEN_CODE, AUTH_INVALID_TOKEN_CODE];

View File

@@ -13,7 +13,7 @@ const Routes = () => {
path="/"
name="Devices"
render={(props) =>
currentToken !== '' && Object.keys(endpoints).length !== 0 ? (
currentToken !== '' && endpoints && Object.keys(endpoints).length !== 0 ? (
<TheLayout {...props} />
) : (
<ToastProvider>

View File

@@ -1,5 +1,6 @@
import * as axios from 'axios';
import axiosRetry from 'axios-retry';
import { LOGOUT_ON_SEC_ERROR_CODES } from 'constants';
const axiosInstance = axios.create();
@@ -27,7 +28,7 @@ axiosInstance.interceptors.response.use(
retries += 1;
localStorage.setItem('sec_retries', retries);
}
if (error.response.data?.ErrorCode === 9) {
if (LOGOUT_ON_SEC_ERROR_CODES.includes(error.response.data?.ErrorCode)) {
localStorage.removeItem('access_token');
localStorage.removeItem('gateway_endpoints');
sessionStorage.clear();