refactor auth and logout
- Pindah hard-code API version ke environment variable - Gunakan helper untuk logout
This commit is contained in:
@@ -12,7 +12,7 @@ export const postLogin = async (
|
|||||||
): Promise<TLoginResponse> => {
|
): Promise<TLoginResponse> => {
|
||||||
const { data } = await api({
|
const { data } = await api({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/v1/auth/login',
|
url: '/auth/login',
|
||||||
data: payload,
|
data: payload,
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -7,27 +7,19 @@ import {
|
|||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { Button } from '../../atoms';
|
import { Button } from '../../atoms';
|
||||||
import { FC, ReactElement } from 'react';
|
import { FC, ReactElement } from 'react';
|
||||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
|
import { useSession } from '@imphnen-frontend-service/utils';
|
||||||
|
|
||||||
export const BackofficeSidebar: FC = (): ReactElement => {
|
export const BackofficeSidebar: FC = (): ReactElement => {
|
||||||
|
const { signOut } = useSession();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
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">
|
||||||
{/* Logo */}
|
|
||||||
<img src="/logos/simple.svg" alt="IMPHNEN Logo" className="w-[150px]" />
|
<img src="/logos/simple.svg" alt="IMPHNEN Logo" className="w-[150px]" />
|
||||||
|
|
||||||
{/* Navigation Menu */}
|
|
||||||
<nav className="flex flex-col gap-4 w-full">
|
<nav className="flex flex-col gap-4 w-full">
|
||||||
<Link
|
<Link
|
||||||
to="/dashboard"
|
to="/dashboard"
|
||||||
@@ -79,12 +71,10 @@ export const BackofficeSidebar: FC = (): ReactElement => {
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Log Out Button */}
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<hr className="mb-5 border-primary-200" />
|
<hr className="mb-5 border-primary-200" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={handleLogout}
|
onClick={signOut}
|
||||||
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