From 032e9d45b3461fbc4e3e473d6569a2794287e8a9 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 24 Nov 2025 09:30:12 +0700 Subject: [PATCH] feat: add logout functionality --- src/components/Navbar.tsx | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index f7cfbb6a..973bf031 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,16 +1,38 @@ 'use client'; +import toast from 'react-hot-toast'; +import { useRouter } from 'next/navigation'; + import { Icon } from '@iconify/react'; import Menu from '@/components/menu/Menu'; import MenuItem from '@/components/menu/MenuItem'; import Button from '@/components/Button'; +import { useAuth } from '@/services/hooks/useAuth'; +import { AuthApi } from '@/services/api/auth'; +import { isResponseError } from '@/lib/api-helper'; + interface NavbarProps { title: string; toggleSidebar?: () => void; } const Navbar = ({ title, toggleSidebar }: NavbarProps) => { + const { setUser } = useAuth(); + const router = useRouter(); + + const logoutClickHandler = async () => { + const logoutRes = await AuthApi.logout(); + + if (isResponseError(logoutRes)) { + toast.error('Gagal logout! Coba lagi!'); + return; + } + + setUser(undefined); + router.replace(process.env.NEXT_PUBLIC_SSO_LOGIN_URL as string); + }; + return (
@@ -42,8 +64,7 @@ const Navbar = ({ title, toggleSidebar }: NavbarProps) => {
- - +