diff --git a/prisma/dev.db b/prisma/dev.db index 841e2e8..12b04eb 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/src/app/api/auth/logout/route.ts b/src/app/api/auth/logout/route.ts new file mode 100644 index 0000000..39ee4e9 --- /dev/null +++ b/src/app/api/auth/logout/route.ts @@ -0,0 +1,20 @@ +import { revalidatePath } from "next/cache"; +import { NextRequest } from "next/server"; +import { logout } from "../actions"; + +const dynamic = 'force-dynamic' + +export async function POST(request: NextRequest) { + await logout() + revalidatePath('/login') + const response = { + success: true, + message: 'Logged out successfully', + }; + + return new Response(JSON.stringify(response), { + headers: { + 'Content-Type': 'application/json', + }, + }); +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index fdec280..fde9763 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -6,6 +6,9 @@ import "./globals.css"; import Navlinks from "./ui/navLinks"; import { ModeToggle } from "./ui/modeToggle"; import { inter } from "./ui/fonts"; +import { LogOutIcon } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import LogoutButton from "./ui/logoutButton"; @@ -15,7 +18,6 @@ export const metadata: Metadata = { }; - export default function RootLayout({ children, }: Readonly<{ @@ -37,7 +39,8 @@ export default function RootLayout({

The self-hosted literary submission tracker.

- +
{children} diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 74eaece..9b0d492 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -17,7 +17,8 @@ import Link from "next/link"; export default function LoginForm() { const router = useRouter() const searchParams = useSearchParams() - const redirect = searchParams.get("from") ?? "submission" + const redirect = searchParams.get("from") ?? "/submission" + console.log(redirect) const form = useForm>({ resolver: zodResolver(loginSchema), }) diff --git a/src/app/tailwind.css b/src/app/tailwind.css index f73f4ea..df53417 100644 --- a/src/app/tailwind.css +++ b/src/app/tailwind.css @@ -740,10 +740,6 @@ body { margin-bottom: 1.5rem; } -.mb-4 { - margin-bottom: 1rem; -} - .ml-2 { margin-left: 0.5rem; } diff --git a/src/app/ui/logoutButton.tsx b/src/app/ui/logoutButton.tsx new file mode 100644 index 0000000..9a7cac1 --- /dev/null +++ b/src/app/ui/logoutButton.tsx @@ -0,0 +1,22 @@ +"use client" +import { Button } from "@/components/ui/button" +import { LogOutIcon } from "lucide-react" + + +async function handleLogout() { + const res = await fetch('/api/auth/logout', { + method: 'POST', + headers: { + 'Content-type': 'application/json', + } + }) + console.log(res) + window.location.reload() +} +export default function LogoutButton() { + return ( + + ) +}