Add debug logging
This commit is contained in:
@@ -2,11 +2,15 @@ import { NextRequest, NextResponse } from "next/server";
|
|||||||
import { verifyPassword, createToken } from "@/lib/auth";
|
import { verifyPassword, createToken } from "@/lib/auth";
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
|
console.log("[LOGIN] Request received");
|
||||||
try {
|
try {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { password } = body;
|
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) {
|
if (!password) {
|
||||||
|
console.log("[LOGIN] Error: No password provided");
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Password is required" },
|
{ error: "Password is required" },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@@ -14,8 +18,10 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isValid = await verifyPassword(password);
|
const isValid = await verifyPassword(password);
|
||||||
|
console.log("[LOGIN] Password valid:", isValid);
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
|
console.log("[LOGIN] Error: Invalid password");
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Invalid password" },
|
{ error: "Invalid password" },
|
||||||
{ status: 401 }
|
{ status: 401 }
|
||||||
@@ -23,6 +29,7 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const token = await createToken();
|
const token = await createToken();
|
||||||
|
console.log("[LOGIN] Token created successfully");
|
||||||
|
|
||||||
const response = NextResponse.json({ success: true });
|
const response = NextResponse.json({ success: true });
|
||||||
response.cookies.set("auth-token", token, {
|
response.cookies.set("auth-token", token, {
|
||||||
@@ -31,12 +38,15 @@ export async function POST(request: NextRequest) {
|
|||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
maxAge: 60 * 60 * 24 * 7, // 7 days
|
maxAge: 60 * 60 * 24 * 7, // 7 days
|
||||||
});
|
});
|
||||||
|
console.log("[LOGIN] Cookie set, returning success");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error("[LOGIN] Error:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Internal server error" },
|
{ error: "Internal server error" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export default function LoginPage() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setError("");
|
setError("");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
console.log("[LOGIN PAGE] Submitting login...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/auth/login", {
|
const res = await fetch("/api/auth/login", {
|
||||||
@@ -24,14 +25,18 @@ export default function LoginPage() {
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ password }),
|
body: JSON.stringify({ password }),
|
||||||
});
|
});
|
||||||
|
console.log("[LOGIN PAGE] Response status:", res.status);
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
console.log("[LOGIN PAGE] Login success, redirecting...");
|
||||||
window.location.href = "/dashboard";
|
window.location.href = "/dashboard";
|
||||||
} else {
|
} else {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
console.log("[LOGIN PAGE] Login failed:", data.error);
|
||||||
setError(data.error || "Login failed");
|
setError(data.error || "Login failed");
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error("[LOGIN PAGE] Error:", err);
|
||||||
setError("Connection error");
|
setError("Connection error");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user