notification + admin panel
This commit is contained in:
12
app/api/admin/check/route.ts
Normal file
12
app/api/admin/check/route.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { isAdminAuthenticated } from '@/lib/admin-auth'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const authenticated = await isAdminAuthenticated()
|
||||
return NextResponse.json({ authenticated })
|
||||
} catch (error) {
|
||||
return NextResponse.json({ authenticated: false })
|
||||
}
|
||||
}
|
||||
|
||||
33
app/api/admin/login/route.ts
Normal file
33
app/api/admin/login/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
16
app/api/admin/logout/route.ts
Normal file
16
app/api/admin/logout/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { clearAdminSession } from '@/lib/admin-auth'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
await clearAdminSession()
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('Error during admin logout:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to process logout' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user