From 6856df59c93b561532c8ee9189f63931423aa87e Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Wed, 30 Jun 2021 11:38:07 +0200 Subject: [PATCH] F OpenNebula/one#5422: Fix sunstone login when error --- src/fireedge/src/client/features/Auth/actions.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/fireedge/src/client/features/Auth/actions.js b/src/fireedge/src/client/features/Auth/actions.js index 2baa093fe6..1f6fe8cc3e 100644 --- a/src/fireedge/src/client/features/Auth/actions.js +++ b/src/fireedge/src/client/features/Auth/actions.js @@ -1,11 +1,12 @@ import { createAsyncThunk, createAction } from '@reduxjs/toolkit' -import { T, JWT_NAME, ONEADMIN_ID, FILTER_POOL } from 'client/constants' import { authService } from 'client/features/Auth/services' import { userService } from 'client/features/One/user/services' import { getGroups } from 'client/features/One/group/actions' import { dismissSnackbar } from 'client/features/General/actions' +import { httpCodes } from 'server/utils/constants' +import { T, JWT_NAME, ONEADMIN_ID, FILTER_POOL } from 'client/constants' import { storage, removeStoreData } from 'client/utils' const login = createAsyncThunk( @@ -28,7 +29,11 @@ const login = createAsyncThunk( isLoginInProgress: !!token && !isOneAdmin } } catch (error) { - return rejectWithValue({ error }) + const { data, status, statusText } = error + + status === httpCodes.unauthorized.id && dispatch(logout(T.SessionExpired)) + + return rejectWithValue({ error: data?.message ?? statusText }) } } ) @@ -95,7 +100,11 @@ const changeGroup = createAsyncThunk( } } } catch (error) { - return rejectWithValue({ error }) + const { data, status, statusText } = error + + status === httpCodes.unauthorized.id && dispatch(logout(T.SessionExpired)) + + return rejectWithValue({ error: data?.message ?? statusText }) } } )