diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index edb1bbd..5e600a0 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -2,11 +2,15 @@ import { NextRequest, NextResponse } from "next/server"; import { verifyPassword, createToken } from "@/lib/auth"; export async function POST(request: NextRequest) { + console.log("[LOGIN] Request received"); try { const body = await request.json(); const { password } = body; + console.log("[LOGIN] Password provided:", password ? "yes" : "no"); + console.log("[LOGIN] APP_ACCESS_PASSWORD env:", process.env.APP_ACCESS_PASSWORD ? "set" : "not set"); if (!password) { + console.log("[LOGIN] Error: No password provided"); return NextResponse.json( { error: "Password is required" }, { status: 400 } @@ -14,8 +18,10 @@ export async function POST(request: NextRequest) { } const isValid = await verifyPassword(password); + console.log("[LOGIN] Password valid:", isValid); if (!isValid) { + console.log("[LOGIN] Error: Invalid password"); return NextResponse.json( { error: "Invalid password" }, { status: 401 } @@ -23,6 +29,7 @@ export async function POST(request: NextRequest) { } const token = await createToken(); + console.log("[LOGIN] Token created successfully"); const response = NextResponse.json({ success: true }); response.cookies.set("auth-token", token, { @@ -31,12 +38,15 @@ export async function POST(request: NextRequest) { sameSite: "lax", maxAge: 60 * 60 * 24 * 7, // 7 days }); + console.log("[LOGIN] Cookie set, returning success"); return response; - } catch { + } catch (error) { + console.error("[LOGIN] Error:", error); return NextResponse.json( { error: "Internal server error" }, { status: 500 } ); } } + diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index c4cf3f6..f493aa9 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -17,6 +17,7 @@ export default function LoginPage() { e.preventDefault(); setError(""); setLoading(true); + console.log("[LOGIN PAGE] Submitting login..."); try { const res = await fetch("/api/auth/login", { @@ -24,14 +25,18 @@ export default function LoginPage() { headers: { "Content-Type": "application/json" }, body: JSON.stringify({ password }), }); + console.log("[LOGIN PAGE] Response status:", res.status); if (res.ok) { + console.log("[LOGIN PAGE] Login success, redirecting..."); window.location.href = "/dashboard"; } else { const data = await res.json(); + console.log("[LOGIN PAGE] Login failed:", data.error); setError(data.error || "Login failed"); } - } catch { + } catch (err) { + console.error("[LOGIN PAGE] Error:", err); setError("Connection error"); } finally { setLoading(false);