This commit is contained in:
2025-09-17 12:16:35 +07:00
parent b51e4a8131
commit bc60728369
7 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
const handleLogOut = () => {
localStorage.removeItem('Auth');
localStorage.removeItem('session');
window.location.replace('/signin');
}
export default handleLogOut;

32
src/Utils/Auth/SignIn.jsx Normal file
View File

@@ -0,0 +1,32 @@
import { login } from '../../api/auth';
import { encryptData } from '../../components/Global/Formatter';
import { NotifAlert } from '../../components/Global/ToastNotif';
const handleSignIn = async (values) => {
const response = await login(values);
// return false
if (response?.status == 200) {
/* you can change this according to your authentication protocol */
let token = JSON.stringify(response.data?.token);
let role = JSON.stringify(response.data?.user?.role_id);
localStorage.setItem('token', token);
response.data.auth = true;
localStorage.setItem('session', encryptData(response?.data));
if (role === `${import.meta.env.VITE_ROLE_VENDOR}`) {
window.location.replace('/dashboard/home-vendor');
} else {
window.location.replace('/dashboard/home');
}
} else {
NotifAlert({
icon: 'error',
title: 'Gagal',
message: response?.data?.message || 'Terjadi kesalahan saat menyimpan data.',
});
}
};
export default handleSignIn;