refactor auth and logout

- Pindah hard-code API version ke environment variable
- Gunakan helper untuk logout
This commit is contained in:
Hafid Nur
2025-04-03 21:59:31 +07:00
parent 38e6d4643b
commit 988476b409
2 changed files with 5 additions and 15 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ export const postLogin = async (
): Promise<TLoginResponse> => {
const { data } = await api({
method: 'POST',
url: '/v1/auth/login',
url: '/auth/login',
data: payload,
});
return data;
@@ -7,27 +7,19 @@ import {
} from '@ant-design/icons';
import { Button } from '../../atoms';
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 => {
const { signOut } = useSession();
const location = useLocation();
const navigate = useNavigate();
const isActive = (path: string) => location.pathname.includes(path);
const handleLogout = () => {
sessionStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
navigate('/');
};
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">
<div className="flex flex-col gap-20 justify-between items-center">
{/* Logo */}
<img src="/logos/simple.svg" alt="IMPHNEN Logo" className="w-[150px]" />
{/* Navigation Menu */}
<nav className="flex flex-col gap-4 w-full">
<Link
to="/dashboard"
@@ -79,12 +71,10 @@ export const BackofficeSidebar: FC = (): ReactElement => {
</nav>
</div>
{/* Log Out Button */}
<div className="w-full">
<hr className="mb-5 border-primary-200" />
<Button
onClick={handleLogout}
onClick={signOut}
variant="text"
className="items-start justify-start gap-3 px-[8px] py-[10px] text-gray-700 hover:text-red-500 transition-colors w-full"
>