Skip to content

Commit

Permalink
Revert "Fixed Unauthorized User Access to Admin Portal (PalisadoesFou…
Browse files Browse the repository at this point in the history
  • Loading branch information
palisadoes authored Mar 25, 2024
1 parent c28a49f commit 971e20a
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/screens/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,37 +255,39 @@ const loginPage = (): JSX.Element => {

/* istanbul ignore next */
if (loginData) {
const { login } = loginData;
const { user, appUserProfile } = login;
const isAdmin: boolean =
appUserProfile.isSuperAdmin ||
(appUserProfile.adminFor.length !== 0 &&
appUserProfile.adminApproved === true);

if (role === 'admin' && !isAdmin) {
toast.warn(t('notAuthorised'));
return;
}
const loggedInUserId = user._id;

setItem('token', login.accessToken);
setItem('refreshToken', login.refreshToken);
setItem('IsLoggedIn', 'TRUE');
setItem('name', `${user.firstName} ${user.lastName}`);
setItem('email', user.email);
setItem('FirstName', user.firstName);
setItem('LastName', user.lastName);
setItem('UserImage', user.image);

if (role === 'admin') {
setItem('id', loggedInUserId);
setItem('SuperAdmin', appUserProfile.isSuperAdmin);
setItem('AdminFor', appUserProfile.adminFor);
if (
loginData.login.appUserProfile.isSuperAdmin ||
(loginData.login.appUserProfile.adminFor.length !== 0 &&
loginData.login.appUserProfile.adminApproved === true)
) {
setItem('FirstName', loginData.login.user.firstName);
setItem('LastName', loginData.login.user.lastName);
setItem('token', loginData.login.accessToken);
setItem('refreshToken', loginData.login.refreshToken);
setItem('id', loginData.login.user._id);
setItem('IsLoggedIn', 'TRUE');
setItem('SuperAdmin', loginData.login.appUserProfile.isSuperAdmin);
setItem('AdminFor', loginData.login.appUserProfile.adminFor);
if (getItem('IsLoggedIn') == 'TRUE') {
navigate(role === 'admin' ? '/orglist' : '/user/organizations');
}
} else {
setItem('userId', loggedInUserId);
setItem('token', loginData.login.accessToken);
setItem('refreshToken', loginData.login.refreshToken);
setItem('userId', loginData.login.user._id);
setItem('IsLoggedIn', 'TRUE');
}
setItem(
'name',
`${loginData.login.user.firstName} ${loginData.login.user.lastName}`,
);
setItem('email', loginData.login.user.email);
setItem('FirstName', loginData.login.user.firstName);
setItem('LastName', loginData.login.user.lastName);
setItem('UserImage', loginData.login.user.image);
if (getItem('IsLoggedIn') == 'TRUE') {
navigate(role === 'admin' ? '/orglist' : '/user/organizations');
}

navigate(role === 'admin' ? '/orglist' : '/user/organizations');
} else {
toast.warn(t('notFound'));
}
Expand Down

0 comments on commit 971e20a

Please sign in to comment.