feat: add login page and API
This commit is contained in:
23
app/api/login/route.ts
Normal file
23
app/api/login/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// app/api/login/route.ts
|
||||
import { NextResponse } from 'next/server';
|
||||
import { AUTH_USERNAME, AUTH_PASSWORD, COOKIE_NAME, COOKIE_MAX_AGE } from '@/lib/constants';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const { username, password } = body;
|
||||
|
||||
if (username === AUTH_USERNAME && password === AUTH_PASSWORD) {
|
||||
const response = NextResponse.json({ success: true });
|
||||
response.cookies.set(COOKIE_NAME, 'ok', {
|
||||
httpOnly: true,
|
||||
maxAge: COOKIE_MAX_AGE,
|
||||
path: '/',
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid credentials' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user