feat: update login feature
This commit is contained in:
parent
1ef498179c
commit
38c5b513ff
|
|
@ -147,119 +147,105 @@ const LoginForm = () => {
|
|||
});
|
||||
const profile = await getProfile(access_token);
|
||||
console.log("PROFILE : ", profile?.data?.data);
|
||||
|
||||
|
||||
Cookies.set("home_path", profile?.data?.data?.homePath, {
|
||||
expires: 1,
|
||||
});
|
||||
Cookies.set(
|
||||
"profile_picture",
|
||||
profile?.data?.data?.profilePictureUrl,
|
||||
{
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
Cookies.set("state", profile?.data?.data?.userLevel?.name, {
|
||||
expires: 1,
|
||||
});
|
||||
Cookies.set(
|
||||
"state-prov",
|
||||
profile.data?.data?.userLevel?.province?.provName,
|
||||
{
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
setCookiesEncrypt("uie", profile?.data?.data?.id, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("urie", profile?.data?.data?.roleId, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("urne", profile?.data?.data?.role?.name, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("ulie", profile?.data?.data?.userLevel?.id, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt(
|
||||
"uplie",
|
||||
profile?.data?.data?.userLevel?.parentLevelId,
|
||||
{
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
setCookiesEncrypt(
|
||||
"ulne",
|
||||
profile?.data?.data?.userLevel?.levelNumber,
|
||||
{
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
setCookiesEncrypt("ufne", profile?.data?.data?.fullname, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("ulnae", profile?.data?.data?.userLevel?.name, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("uinse", profile?.data?.data?.instituteId, {
|
||||
expires: 1,
|
||||
});
|
||||
console.log("ssaddd", profile?.data?.data?.roleId);
|
||||
if (
|
||||
profile?.data?.data?.isInternational == true ||
|
||||
profile?.data?.data?.isActive == false ||
|
||||
profile?.data?.data?.isDelete == true
|
||||
Number(profile?.data?.data?.roleId) == 2 ||
|
||||
Number(profile?.data?.data?.roleId) == 3 ||
|
||||
Number(profile?.data?.data?.roleId) == 4 ||
|
||||
Number(profile?.data?.data?.roleId) == 9 ||
|
||||
Number(profile?.data?.data?.roleId) == 10 ||
|
||||
Number(profile?.data?.data?.roleId) == 11 ||
|
||||
Number(profile?.data?.data?.roleId) == 12 ||
|
||||
Number(profile?.data?.data?.roleId) == 18 ||
|
||||
Number(profile?.data?.data?.roleId) == 19
|
||||
) {
|
||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
||||
Cookies.remove(cookieName);
|
||||
});
|
||||
warning(
|
||||
"Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri",
|
||||
"/auth/login"
|
||||
);
|
||||
} else {
|
||||
Cookies.set("home_path", profile?.data?.data?.homePath, {
|
||||
expires: 1,
|
||||
});
|
||||
Cookies.set(
|
||||
"profile_picture",
|
||||
profile?.data?.data?.profilePictureUrl,
|
||||
{
|
||||
if (profile?.data?.data?.roleId === 18) {
|
||||
window.location.href = "/in/dashboard/executive-data";
|
||||
// router.push('/admin/dashboard');
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
Cookies.set("state", profile?.data?.data?.userLevel?.name, {
|
||||
expires: 1,
|
||||
});
|
||||
Cookies.set(
|
||||
"state-prov",
|
||||
profile.data?.data?.userLevel?.province?.provName,
|
||||
{
|
||||
});
|
||||
} else if (profile?.data?.data?.roleId === 2) {
|
||||
window.location.href = "/in/dashboard/executive";
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
setCookiesEncrypt("uie", profile?.data?.data?.id, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("urie", profile?.data?.data?.roleId, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("urne", profile?.data?.data?.role?.name, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("ulie", profile?.data?.data?.userLevel?.id, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt(
|
||||
"uplie",
|
||||
profile?.data?.data?.userLevel?.parentLevelId,
|
||||
{
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
setCookiesEncrypt(
|
||||
"ulne",
|
||||
profile?.data?.data?.userLevel?.levelNumber,
|
||||
{
|
||||
expires: 1,
|
||||
}
|
||||
);
|
||||
setCookiesEncrypt("ufne", profile?.data?.data?.fullname, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("ulnae", profile?.data?.data?.userLevel?.name, {
|
||||
expires: 1,
|
||||
});
|
||||
setCookiesEncrypt("uinse", profile?.data?.data?.instituteId, {
|
||||
expires: 1,
|
||||
});
|
||||
console.log("ssaddd", profile?.data?.data?.roleId);
|
||||
if (
|
||||
Number(profile?.data?.data?.roleId) == 2 ||
|
||||
Number(profile?.data?.data?.roleId) == 3 ||
|
||||
Number(profile?.data?.data?.roleId) == 4 ||
|
||||
Number(profile?.data?.data?.roleId) == 9 ||
|
||||
Number(profile?.data?.data?.roleId) == 10 ||
|
||||
Number(profile?.data?.data?.roleId) == 11 ||
|
||||
Number(profile?.data?.data?.roleId) == 12 ||
|
||||
Number(profile?.data?.data?.roleId) == 18 ||
|
||||
Number(profile?.data?.data?.roleId) == 19
|
||||
});
|
||||
} else if (
|
||||
profile?.data?.data?.userLevel?.id == 794 ||
|
||||
profile?.data?.data?.userLevel?.parentLevelId == 761
|
||||
) {
|
||||
if (profile?.data?.data?.roleId === 18) {
|
||||
window.location.href = "/in/dashboard/executive-data";
|
||||
// router.push('/admin/dashboard');
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
} else if (profile?.data?.data?.roleId === 2) {
|
||||
window.location.href = "/in/dashboard/executive";
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
} else if (
|
||||
profile?.data?.data?.userLevel?.id == 794 ||
|
||||
profile?.data?.data?.userLevel?.parentLevelId == 761
|
||||
) {
|
||||
window.location.href = "/in/dashboard";
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
} else {
|
||||
window.location.href = "/in/dashboard";
|
||||
// router.push('/admin/dashboard');
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
}
|
||||
window.location.href = "/in/dashboard";
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
} else {
|
||||
window.location.href = "/";
|
||||
window.location.href = "/in/dashboard";
|
||||
// router.push('/admin/dashboard');
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
window.location.href = "/";
|
||||
Cookies.set("status", "login", {
|
||||
expires: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
|
|
|
|||
|
|
@ -105,14 +105,14 @@ export const useAuth = (): AuthContextType => {
|
|||
}
|
||||
|
||||
// Validate user eligibility
|
||||
if (!isUserEligible(profile)) {
|
||||
clearAllCookies();
|
||||
warning(
|
||||
"Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri",
|
||||
"/auth"
|
||||
);
|
||||
return;
|
||||
}
|
||||
// if (!isUserEligible(profile)) {
|
||||
// clearAllCookies();
|
||||
// warning(
|
||||
// "Akun Anda tidak dapat digunakan untuk masuk ke MediaHub Polri",
|
||||
// "/auth"
|
||||
// );
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Set profile cookies
|
||||
setProfileCookies(profile);
|
||||
|
|
|
|||
Loading…
Reference in New Issue