import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/db';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { token } = body;
if (!token) {
return NextResponse.json(
{ success: false, error: 'Verification token is required' },
{ status: 400 }
);
}
const success = await db.verifyUserByToken(token);
if (success) {
return NextResponse.json({
success: true,
message: 'Email verified successfully',
});
} else {
return NextResponse.json(
{ success: false, error: 'Invalid or expired verification token' },
{ status: 400 }
);
}
} catch (error: any) {
console.error('Email verification error:', error);
return NextResponse.json(
{ success: false, error: 'Verification failed' },
{ status: 500 }
);
}
}