refac: gera url de reset de senha com base no .env

This commit is contained in:
2026-05-18 19:28:14 -05:00
parent 7153caa0ac
commit c1ad6b4cfe
5 changed files with 22 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import { Prisma } from '@prisma/client'
import { createError, readBody, setResponseStatus, type H3Event } from 'h3'
import { createError, getRequestURL, readBody, setResponseStatus, type H3Event } from 'h3'
import { signAccessToken } from './jwt'
import { getAuthRuntimeConfig } from './auth-config'
@@ -202,6 +202,7 @@ export async function handleForgotPassword(event: H3Event) {
const expiresAt = new Date(now.getTime() + config.passwordResetTtlSec * 1000)
const rawResetToken = generateRawPasswordResetToken()
const tokenHash = hashPasswordResetToken(rawResetToken, config.passwordResetTokenPepper)
const resetBaseUrl = config.passwordResetBaseUrl || getRequestURL(event).origin
const user = await prisma.user.findUnique({
where: { email },
@@ -233,7 +234,7 @@ export async function handleForgotPassword(event: H3Event) {
message: 'If the email exists, recovery instructions were generated',
recovery: {
reset_token: rawResetToken,
reset_url: buildPasswordResetPreviewUrl(config.issuer, rawResetToken),
reset_url: buildPasswordResetPreviewUrl(resetBaseUrl, rawResetToken),
expires_in: config.passwordResetTtlSec
}
}