Compare commits
3 Commits
4fc87b7134
...
879afd94de
| Author | SHA1 | Date | |
|---|---|---|---|
| 879afd94de | |||
| 39124f0db4 | |||
| 0c9ca45b36 |
@ -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;
|
|
||||||
7
app/(safe-mode-page)/auth/logout/route.tsx
Normal file
7
app/(safe-mode-page)/auth/logout/route.tsx
Normal 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);
|
||||||
|
};
|
||||||
@ -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>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -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,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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 (
|
||||||
|
|||||||
Reference in New Issue
Block a user