Compare commits

..

3 Commits

Author SHA1 Message Date
879afd94de 🩹 fix: resolve build error
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 1m4s
2026-02-18 12:56:29 +07:00
39124f0db4 🚸 ux: improve logout flow completely 2026-02-18 12:53:58 +07:00
0c9ca45b36 🥅 fix: handle logout failure warning 2026-02-18 12:27:24 +07:00
7 changed files with 35 additions and 17 deletions

View File

@ -1,9 +0,0 @@
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
const page = async () => {
(await cookies()).delete("auth_token");
redirect("/");
};
export default page;

View File

@ -0,0 +1,7 @@
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export const GET = async (request: Request) => {
(await cookies()).delete("auth_token");
return NextResponse.redirect(new URL("/", request.url), 303);
};

View File

@ -1,6 +1,7 @@
import type { Metadata } from "next"; import type { Metadata } from "next";
import { Geist, Geist_Mono, Inter } from "next/font/google"; import { Geist, Geist_Mono, Inter } from "next/font/google";
import "./globals.css"; import "./globals.css";
import { Toaster } from "@/shared/libs/shadcn/ui/sonner";
const inter = Inter({ subsets: ["latin"], variable: "--font-sans" }); const inter = Inter({ subsets: ["latin"], variable: "--font-sans" });
@ -29,7 +30,8 @@ export default function RootLayout({
<body <body
className={`${geistSans.variable} ${geistMono.variable} antialiased`} className={`${geistSans.variable} ${geistMono.variable} antialiased`}
> >
{children} <main>{children}</main>
<Toaster />
</body> </body>
</html> </html>
); );

View File

@ -47,6 +47,7 @@ export const submitProviderCallback = async (
} catch (error) { } catch (error) {
return { return {
success: false, success: false,
status: 500,
message: "Error submitting provider callback", message: "Error submitting provider callback",
error: error, error: error,
}; };

View File

@ -1,7 +1,6 @@
"use server"; "use server";
import { backendFetch, BackendResponse } from "@/shared/helpers/backendFetch"; import { backendFetch, BackendResponse } from "@/shared/helpers/backendFetch";
import { cookies } from "next/headers";
export const logout = async () => { export const logout = async () => {
const res = (await backendFetch("auth/logout", { const res = (await backendFetch("auth/logout", {
@ -9,10 +8,9 @@ export const logout = async () => {
})) as BackendResponse; })) as BackendResponse;
if (res.success) { if (res.success) {
(await cookies()).delete("auth_token");
return { return {
success: true, success: true,
message: "Logged out successfully", message: "Logout successful",
}; };
} else { } else {
return { return {

View File

@ -2,7 +2,6 @@
import { backendFetch, BackendResponse } from "@/shared/helpers/backendFetch"; import { backendFetch, BackendResponse } from "@/shared/helpers/backendFetch";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { cookies } from "next/headers";
export interface UserSession { export interface UserSession {
id: string; id: string;

View File

@ -11,7 +11,9 @@ import {
import { Spinner } from "@/shared/libs/shadcn/ui/spinner"; import { Spinner } from "@/shared/libs/shadcn/ui/spinner";
import { logout } from "@/shared/models/auth/logout"; import { logout } from "@/shared/models/auth/logout";
import { Button } from "@base-ui/react"; import { Button } from "@base-ui/react";
import { useRouter } from "next/navigation";
import React from "react"; import React from "react";
import { toast } from "sonner";
const LogoutAlert = ({ const LogoutAlert = ({
openState, openState,
@ -20,12 +22,30 @@ const LogoutAlert = ({
openState: boolean; openState: boolean;
setOpenState: React.Dispatch<React.SetStateAction<boolean>>; setOpenState: React.Dispatch<React.SetStateAction<boolean>>;
}) => { }) => {
const router = useRouter();
const [isLoading, setIsLoading] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false);
const continueLogout = async () => { const continueLogout = async () => {
setIsLoading(true); setIsLoading(true);
await logout().then((res) => const res = await logout();
res.success ? window.location.reload() : setIsLoading(false), 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,
});
} else {
toast.success(res.message || "Logout successful", {
position: "bottom-right",
description: "You have been logged out successfully.",
richColors: true,
});
router.push("/auth/logout");
setTimeout(() => {
window.location.reload();
}, 2000);
}
}; };
return ( return (