🥅 fix: handle logout failure warning

This commit is contained in:
2026-02-18 12:27:24 +07:00
parent 4fc87b7134
commit 0c9ca45b36
3 changed files with 16 additions and 9 deletions

View File

@ -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,

View File

@ -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 (