diff --git a/frontend/src/api/authService.js b/frontend/src/api/authService.js index 0a03486..15d8fae 100644 --- a/frontend/src/api/authService.js +++ b/frontend/src/api/authService.js @@ -1,16 +1,21 @@ import api from "./axios"; export async function login(payload) { - const { data } = await api.post("/auth/login", payload); - return data; + const { data } = await api.post("/auth/login", payload); + return data; } export async function signup(payload) { - const { data } = await api.post("/auth/register", payload); - return data; + const { data } = await api.post("/auth/register", payload); + return data; +} + +export async function logout() { + const { data } = await api.post("/auth/logout"); + return data; } export async function getMe() { - const { data } = await api.get("/auth/me"); - return data; + const { data } = await api.get("/auth/me"); + return data; } diff --git a/frontend/src/app/router.jsx b/frontend/src/app/router.jsx index 7c05760..bdde82f 100644 --- a/frontend/src/app/router.jsx +++ b/frontend/src/app/router.jsx @@ -47,7 +47,7 @@ export function AppRouter() { + } @@ -60,22 +60,18 @@ export function AppRouter() { } /> + } /> + } /> } -/> - } -/> - - - - } -/> + path="/approvals" + element={ + + + + } + /> { - setUser(null); - setToken(null); - localStorage.removeItem("token"); - localStorage.removeItem("auth_user"); - window.location.href = "/login"; + const logout = useCallback(async () => { + try { + await logoutRequest(); + } catch { + // proceed with client-side cleanup even if server call fails + } finally { + setUser(null); + setToken(null); + localStorage.removeItem("token"); + localStorage.removeItem("auth_user"); + window.location.href = "/login"; + } }, []); const switchRole = useCallback((role) => {