Files
MOPC-Portal/src/app/api/auth/check-email/route.ts

27 lines
832 B
TypeScript
Raw Normal View History

import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
/**
* Pre-check whether an email exists before sending a magic link.
* This is a closed platform (no self-registration) so revealing
* email existence is acceptable and helps users who mistype.
*/
export async function POST(req: NextRequest) {
try {
const { email } = await req.json()
if (!email || typeof email !== 'string') {
return NextResponse.json({ exists: false }, { status: 400 })
}
const user = await prisma.user.findUnique({
where: { email: email.toLowerCase().trim() },
select: { status: true },
})
const exists = !!user && user.status !== 'SUSPENDED'
return NextResponse.json({ exists })
} catch {
return NextResponse.json({ exists: false }, { status: 500 })
}
}