diff --git a/backend/src/routes/auth.js b/backend/src/routes/auth.js
index fd2106f..03609d2 100644
--- a/backend/src/routes/auth.js
+++ b/backend/src/routes/auth.js
@@ -202,6 +202,9 @@ module.exports = (pool, query) => {
message: 'Login successful',
userId: userId,
isAdmin: userInfo.rows[0].is_admin,
+ firstname: userInfo.rows[0].first_name,
+ lastname: userInfo.rows[0].last_name,
+ email: userInfo.rows[0].email,
apiKey: apiKey
});
} catch (error) {
diff --git a/frontend/src/features/auth/authSlice.js b/frontend/src/features/auth/authSlice.js
index 24aa1de..65af407 100644
--- a/frontend/src/features/auth/authSlice.js
+++ b/frontend/src/features/auth/authSlice.js
@@ -2,6 +2,7 @@ import { createSlice } from '@reduxjs/toolkit';
const initialState = {
user: JSON.parse(localStorage.getItem('user')) || null,
+ userData: JSON.parse(localStorage.getItem('userData')) || null,
apiKey: localStorage.getItem('apiKey') || null,
isAdmin: localStorage.getItem('isAdmin') === 'true',
isAuthenticated: !!localStorage.getItem('apiKey'),
@@ -21,11 +22,24 @@ export const authSlice = createSlice({
state.loading = false;
state.isAuthenticated = true;
state.user = action.payload.user;
+ state.userData = {
+ id: action.payload.user,
+ apiKey: action.payload.apiKey,
+ email: action.payload.email,
+ firstname: action.payload.firstname,
+ lastname: action.payload.lastname,
+ isAdmin: action.payload.isAdmin
+ };
state.apiKey = action.payload.apiKey;
state.isAdmin = action.payload.isAdmin;
localStorage.setItem('apiKey', action.payload.apiKey);
localStorage.setItem('isAdmin', action.payload.isAdmin);
localStorage.setItem('user', JSON.stringify(action.payload.user));
+ localStorage.setItem('userData', JSON.stringify({
+ id: action.payload.user,
+ apiKey: action.payload.apiKey,
+ isAdmin: action.payload.isAdmin
+ }));
},
loginFailed: (state, action) => {
state.loading = false;
@@ -34,11 +48,13 @@ export const authSlice = createSlice({
logout: (state) => {
state.isAuthenticated = false;
state.user = null;
+ state.userData = null;
state.apiKey = null;
state.isAdmin = false;
localStorage.removeItem('apiKey');
localStorage.removeItem('isAdmin');
localStorage.removeItem('user');
+ localStorage.removeItem('userData');
},
clearError: (state) => {
state.error = null;
diff --git a/frontend/src/hooks/apiHooks.js b/frontend/src/hooks/apiHooks.js
index 25aa4af..2538b0c 100644
--- a/frontend/src/hooks/apiHooks.js
+++ b/frontend/src/hooks/apiHooks.js
@@ -143,7 +143,7 @@ export const useVerifyCode = () => {
return useMutation({
mutationFn: (verifyData) => authService.verifyCode(verifyData),
onSuccess: (data) => {
- login(data.userId, data.apiKey, data.isAdmin);
+ login(data.userId, data.apiKey, data.isAdmin, data.email, data?.firstname, data?.lastname);
notification.showNotification('Login successful', 'success');
},
onError: (error) => {
diff --git a/frontend/src/hooks/reduxHooks.js b/frontend/src/hooks/reduxHooks.js
index 2c3b54a..9badac5 100644
--- a/frontend/src/hooks/reduxHooks.js
+++ b/frontend/src/hooks/reduxHooks.js
@@ -60,6 +60,7 @@ export const useAuth = () => {
const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated);
const isAdmin = useAppSelector((state) => state.auth.isAdmin);
const user = useAppSelector((state) => state.auth.user);
+ const userData = useAppSelector((state) => state.auth.userData);
const apiKey = useAppSelector((state) => state.auth.apiKey);
const loading = useAppSelector((state) => state.auth.loading);
const error = useAppSelector((state) => state.auth.error);
@@ -69,14 +70,14 @@ export const useAuth = () => {
isAuthenticated,
isAdmin,
user,
+ userData,
apiKey,
loading,
error,
- login: (user, apiKey, isAdmin) =>
+ login: (user, apiKey, isAdmin, email, firstname = "", lastname = "") =>
dispatch({
type: 'auth/loginSuccess',
- payload: { user, apiKey, isAdmin }
- }),
+ payload: { user, apiKey, isAdmin, email, firstname, lastname}}),
logout: () => dispatch({ type: 'auth/logout' }),
clearError: () => dispatch({ type: 'auth/clearError' }),
};
diff --git a/frontend/src/pages/Admin/CustomersPage.jsx b/frontend/src/pages/Admin/CustomersPage.jsx
index 40d00cd..88f4a38 100644
--- a/frontend/src/pages/Admin/CustomersPage.jsx
+++ b/frontend/src/pages/Admin/CustomersPage.jsx
@@ -39,7 +39,7 @@ import { format } from 'date-fns';
import EmailDialog from '@components/EmailDialog';
import { useAuth } from '@hooks/reduxHooks';
const AdminCustomersPage = () => {
- const { user, isAuthenticated } = useAuth();
+ const { user, userData, isAuthenticated } = useAuth();
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);
const [search, setSearch] = useState('');
@@ -329,12 +329,12 @@ const AdminCustomersPage = () => {
}
- label={`${formData.is_disabled ? "Account is disabled" : "Account is active"}` + `${user === currentUser.id && formData.is_admin? " (Current user can\'t disabled themselves)" : "" }`}
+ label={`${formData.is_disabled ? "Account is disabled" : "Account is active"}` + `${userData?.id === currentUser.id && formData.is_admin? " (Current user can\'t disabled themselves)" : "" }`}
sx={{ my: 2, display: 'block' }}
/>
{
}
- label={`${formData.is_admin ? "Account is Admin" : "Account is not Admin"}` + `${user === currentUser.id && formData.is_admin? " (Admin can't downgrade themselves)" : "" }`}
+ label={`${formData.is_admin ? "Account is Admin" : "Account is not Admin"}` + `${userData?.id === currentUser.id && formData.is_admin? " (Admin can't downgrade themselves)" : "" }`}
sx={{ my: 2, display: 'block' }}
/>