refac: gera url de reset de senha com base no .env
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user