From 0c9ca45b36883204066857677dce7c6e4afc5ba4 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Wed, 18 Feb 2026 12:27:24 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20fix:=20handle=20logout=20failure?= =?UTF-8?q?=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/layout.tsx | 4 +++- shared/models/auth/logout.ts | 7 ++----- shared/widgets/navbar/components/LogoutAlert.tsx | 14 +++++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index f65b89c..b87e432 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono, Inter } from "next/font/google"; import "./globals.css"; +import { Toaster } from "@/shared/libs/shadcn/ui/sonner"; const inter = Inter({ subsets: ["latin"], variable: "--font-sans" }); @@ -29,7 +30,8 @@ export default function RootLayout({ - {children} +
{children}
+ ); diff --git a/shared/models/auth/logout.ts b/shared/models/auth/logout.ts index 23ab5bf..92ffd02 100644 --- a/shared/models/auth/logout.ts +++ b/shared/models/auth/logout.ts @@ -2,6 +2,7 @@ import { backendFetch, BackendResponse } from "@/shared/helpers/backendFetch"; import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; export const logout = async () => { const res = (await backendFetch("auth/logout", { @@ -9,11 +10,7 @@ export const logout = async () => { })) as BackendResponse; if (res.success) { - (await cookies()).delete("auth_token"); - return { - success: true, - message: "Logged out successfully", - }; + redirect("/auth/logout"); } else { return { success: false, diff --git a/shared/widgets/navbar/components/LogoutAlert.tsx b/shared/widgets/navbar/components/LogoutAlert.tsx index b15bd34..9595904 100644 --- a/shared/widgets/navbar/components/LogoutAlert.tsx +++ b/shared/widgets/navbar/components/LogoutAlert.tsx @@ -12,6 +12,7 @@ import { Spinner } from "@/shared/libs/shadcn/ui/spinner"; import { logout } from "@/shared/models/auth/logout"; import { Button } from "@base-ui/react"; import React from "react"; +import { toast } from "sonner"; const LogoutAlert = ({ openState, @@ -23,9 +24,16 @@ const LogoutAlert = ({ const [isLoading, setIsLoading] = React.useState(false); const continueLogout = async () => { setIsLoading(true); - await logout().then((res) => - res.success ? window.location.reload() : setIsLoading(false), - ); + const res = await logout(); + if (!res.success) { + setIsLoading(false); + toast.error(res.message || "Logout failed", { + position: "bottom-right", + description: + "An error occurred while logging out. Please try again later.", + richColors: true, + }); + } }; return (