Add src
This commit is contained in:
7
src/Utils/Auth/Logout.jsx
Normal file
7
src/Utils/Auth/Logout.jsx
Normal 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
32
src/Utils/Auth/SignIn.jsx
Normal 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;
|
||||
Reference in New Issue
Block a user