Spaces:
Sleeping
Sleeping
File size: 1,297 Bytes
dc06740 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import { NextResponse } from 'next/server';
export async function POST(request: Request) {
try {
const { password, name, email } = await request.json();
const userPassword = process.env.USER_PASSWORD || 'demo';
const adminPassword = process.env.ADMIN_PASSWORD || 'admin';
const adminName = process.env.ADMIN_NAME || 'Admin';
const adminEmail = process.env.ADMIN_EMAIL || 'admin@example.com';
// Verify credentials first
let isValidUser = false;
let isDeveloper = false;
if (password === userPassword) {
isValidUser = true;
} else if (password === adminPassword && name === adminName && email === adminEmail) {
isValidUser = true;
isDeveloper = true;
}
if (!isValidUser) {
return NextResponse.json(
{ error: 'Invalid credentials' },
{ status: 401 }
);
}
// Only return what's needed for the authenticated user
return NextResponse.json({
success: true,
isDeveloper,
adminName: isDeveloper ? adminName : undefined,
adminEmail: isDeveloper ? adminEmail : undefined,
});
} catch (error) {
console.error('Error verifying credentials:', error);
return NextResponse.json(
{ error: 'Authentication failed' },
{ status: 500 }
);
}
}
|