UNPKG

nuxt-users

Version:

A comprehensive user management module for Nuxt 3 and Nuxt 4 applications with authentication, authorization, database support, and CLI tools

27 lines (26 loc) 950 B
import { defineEventHandler, readBody, createError } from "h3"; import { sendPasswordResetLink } from "../../../services/password.js"; export default defineEventHandler(async (event) => { const body = await readBody(event); const { email } = body; if (!email || typeof email !== "string") { throw createError({ statusCode: 400, statusMessage: "Email is required and must be a string." }); } try { await sendPasswordResetLink(email, event.context.nuxtUsers); return { message: "If a user with that email exists, a password reset link has been sent." }; } catch (error) { if (error instanceof Error) { console.error("[Nuxt Users] Error in forgot-password endpoint:", error.message); } else { console.error("[Nuxt Users] Error in forgot-password endpoint:", error); } throw createError({ statusCode: 500, statusMessage: "An internal server error occurred." }); } });