feat(backoffice): implement login and logout
- Tambah fitur login dan logout pada Backoffice - Ubah port development server dan atasi CORS - Update type login response - Update component Input agar toggle password berfungsi dengan benar
This commit is contained in:
@@ -16,6 +16,10 @@ export const Components: FC = (): ReactElement => {
|
|||||||
console.log(payload); // for debugging
|
console.log(payload); // for debugging
|
||||||
const response = await postLogin(payload);
|
const response = await postLogin(payload);
|
||||||
|
|
||||||
|
const { access_token, refresh_token } = response.data.token;
|
||||||
|
sessionStorage.setItem('access_token', access_token);
|
||||||
|
localStorage.setItem('refresh_token', refresh_token);
|
||||||
|
|
||||||
console.log('Login successful:', response); // for debugging
|
console.log('Login successful:', response); // for debugging
|
||||||
navigate('/dashboard');
|
navigate('/dashboard');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -39,6 +43,7 @@ export const Components: FC = (): ReactElement => {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
autoFocus
|
||||||
/>
|
/>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Password"
|
label="Password"
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ export default defineConfig(() => ({
|
|||||||
root: __dirname,
|
root: __dirname,
|
||||||
cacheDir: '../../node_modules/.vite/apps/backoffice',
|
cacheDir: '../../node_modules/.vite/apps/backoffice',
|
||||||
server: {
|
server: {
|
||||||
port: 4200,
|
port: 3000,
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
},
|
},
|
||||||
preview: {
|
preview: {
|
||||||
port: 4300,
|
port: 3001,
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
},
|
},
|
||||||
plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
|
plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
|
||||||
|
|||||||
@@ -10,9 +10,27 @@ export type TLoginResponse = {
|
|||||||
refresh_token: string;
|
refresh_token: string;
|
||||||
};
|
};
|
||||||
user: {
|
user: {
|
||||||
|
role: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
permission: [
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
};
|
||||||
fullname: string;
|
fullname: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
avatar: string;
|
||||||
|
phone_number: string;
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
|
gender: string;
|
||||||
|
birthdate: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ export const Input: FC<TInputProps> = ({
|
|||||||
}): ReactElement => {
|
}): ReactElement => {
|
||||||
const [showPassword, setShowPassword] = useState(false); // State for password visibility
|
const [showPassword, setShowPassword] = useState(false); // State for password visibility
|
||||||
|
|
||||||
const togglePasswordVisibility = () => {
|
const togglePasswordVisibility = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
if (!disabled) setShowPassword((prev) => !prev);
|
if (!disabled) setShowPassword((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ export const Input: FC<TInputProps> = ({
|
|||||||
{type === 'password' && (
|
{type === 'password' && (
|
||||||
<div className="absolute end-0 px-[12px] h-full flex items-center">
|
<div className="absolute end-0 px-[12px] h-full flex items-center">
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
variant="text"
|
variant="text"
|
||||||
size={size}
|
size={size}
|
||||||
onClick={togglePasswordVisibility}
|
onClick={togglePasswordVisibility}
|
||||||
|
|||||||
@@ -14,6 +14,13 @@ export const BackofficeSidebar: FC = (): ReactElement => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isActive = (path: string) => location.pathname.includes(path);
|
const isActive = (path: string) => location.pathname.includes(path);
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
sessionStorage.removeItem('access_token');
|
||||||
|
localStorage.removeItem('refresh_token');
|
||||||
|
|
||||||
|
navigate('/');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="sticky top-0 left-0 w-[280px] bg-white min-h-screen py-[60px] px-[28px] shadow-xl flex flex-col justify-between">
|
<aside className="sticky top-0 left-0 w-[280px] bg-white min-h-screen py-[60px] px-[28px] shadow-xl flex flex-col justify-between">
|
||||||
<div className="flex flex-col gap-20 justify-between items-center">
|
<div className="flex flex-col gap-20 justify-between items-center">
|
||||||
@@ -77,9 +84,7 @@ export const BackofficeSidebar: FC = (): ReactElement => {
|
|||||||
<hr className="mb-5 border-primary-200" />
|
<hr className="mb-5 border-primary-200" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={handleLogout}
|
||||||
navigate('/');
|
|
||||||
}}
|
|
||||||
variant="text"
|
variant="text"
|
||||||
className="items-start justify-start gap-3 px-[8px] py-[10px] text-gray-700 hover:text-red-500 transition-colors w-full"
|
className="items-start justify-start gap-3 px-[8px] py-[10px] text-gray-700 hover:text-red-500 transition-colors w-full"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user