34 lines
818 B
TypeScript
34 lines
818 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { verifyAdminPassword, setAdminSession } from '@/lib/admin-auth'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json()
|
|
const { password } = body
|
|
|
|
if (!password) {
|
|
return NextResponse.json(
|
|
{ error: 'Password is required' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
if (verifyAdminPassword(password)) {
|
|
await setAdminSession()
|
|
return NextResponse.json({ success: true })
|
|
} else {
|
|
return NextResponse.json(
|
|
{ error: 'Invalid password' },
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
} catch (error) {
|
|
console.error('Error during admin login:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to process login' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|