feat(auth): Enhance authentication flow and settings management

This commit is contained in:
decolua
2026-02-05 11:26:11 +07:00
parent 0a026c7af6
commit 249fc28c49
6 changed files with 129 additions and 60 deletions

View File

@@ -0,0 +1,12 @@
import { NextResponse } from "next/server";
import { getSettings } from "@/lib/localDb";
export async function GET() {
try {
const settings = await getSettings();
const requireLogin = settings.requireLogin !== false;
return NextResponse.json({ requireLogin });
} catch (error) {
return NextResponse.json({ requireLogin: true }, { status: 200 });
}
}

View File

@@ -5,13 +5,15 @@ import bcrypt from "bcryptjs";
export async function GET() {
try {
const settings = await getSettings();
// Don't return the password hash to the client
const { password, ...safeSettings } = settings;
// Add ENABLE_REQUEST_LOGS from env
const enableRequestLogs = process.env.ENABLE_REQUEST_LOGS === "true";
return NextResponse.json({ ...safeSettings, enableRequestLogs });
return NextResponse.json({
...safeSettings,
enableRequestLogs,
hasPassword: !!password
});
} catch (error) {
console.log("Error getting settings:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
@@ -37,8 +39,9 @@ export async function PATCH(request) {
return NextResponse.json({ error: "Invalid current password" }, { status: 401 });
}
} else {
// First time setting password, check if it matches default 123456
if (body.currentPassword !== "123456") {
// First time setting password, no current password needed
// Allow empty currentPassword or default "123456"
if (body.currentPassword && body.currentPassword !== "123456") {
return NextResponse.json({ error: "Invalid current password" }, { status: 401 });
}
}