chore: Secure routes with auth middleware, update text and fix minor bugs

This commit is contained in:
2026-08-03 17:55:20 +05:30
parent 62d15c85f6
commit c2fab50749
68 changed files with 2515 additions and 6808 deletions

View File

@@ -0,0 +1,43 @@
import { NextResponse } from 'next/server';
export async function POST(request: Request) {
try {
const body = await request.json();
const { email, password } = body;
let role = null;
if (email === "demo@pragativeer.com" && password === "Pv9#kL2$mQ8!vX4@") {
role = "user";
} else if (email === "admin@pragativeer.com" && password === "admin123") {
role = "admin";
}
if (role) {
const response = NextResponse.json({ success: true, role });
// Set HttpOnly cookie
response.cookies.set({
name: 'auth_token',
value: role,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/',
maxAge: 60 * 60 * 24 * 7 // 1 week
});
return response;
}
return NextResponse.json(
{ success: false, error: 'Invalid email or password' },
{ status: 401 }
);
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Bad request' },
{ status: 400 }
);
}
}