Initial Commit

Commit pertama, memindahkan repository dari github ke gitea.
This commit is contained in:
dicky arya pratama committed 2026-11-04 17:18:53 +07:00
commit 13a47fbebf
41 files changed
+12327

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import { NextResponse } from "next/server";
import { verifyUserCredentials, createSessionToken, SESSION_COOKIE_NAME } from "@/lib/auth";
export async function POST(req: Request) {
try {
const { username, password } = await req.json();
if (!username || !password) {
return NextResponse.json(
{ error: "Username and password are required" },
{ status: 400 }
);
}
const authResult = await verifyUserCredentials(username, password);
if (!authResult.success) {
return NextResponse.json(
{ error: "Invalid username or password" },
{ status: 401 }
);
}
const token = createSessionToken(username);
const response = NextResponse.json({
success: true,
user: authResult.user || { username },
});
response.cookies.set(SESSION_COOKIE_NAME, token, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",
maxAge: 60 * 60 * 24 * 7, // 7 days
});
return response;
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Unknown error";
return NextResponse.json({ error: message }, { status: 500 });
}
}
+8
View File
@@ -0,0 +1,8 @@
import { NextResponse } from "next/server";
import { SESSION_COOKIE_NAME } from "@/lib/auth";
export async function POST() {
const response = NextResponse.json({ success: true });
response.cookies.delete(SESSION_COOKIE_NAME);
return response;
}
+10
View File
@@ -0,0 +1,10 @@
import { NextResponse } from "next/server";
import { isAuthenticated } from "@/lib/auth";
export async function GET() {
const authed = await isAuthenticated();
if (!authed) {
return NextResponse.json({ authenticated: false }, { status: 401 });
}
return NextResponse.json({ authenticated: true, user: { username: "Aghatis" } });
}