// server/api/auth/login.post.js import { connectDB } from "../../utils/mongoose.js"; import { validateBody } from "../../utils/validateBody.js"; import { emailSchema } from "../../utils/schemas.js"; import { sendMagicLink } from "../../utils/magicLink.js"; export default defineEventHandler(async (event) => { await connectDB(); const { email } = await validateBody(event, emailSchema); const GENERIC_MESSAGE = "If this email is registered, we've sent a login link."; try { await sendMagicLink(email); return { success: true, message: GENERIC_MESSAGE, }; } catch (error) { console.error("Failed to send email:", error); throw createError({ statusCode: 500, statusMessage: "Failed to send login email. Please try again.", }); } });