mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 11:33:07 +00:00
Deliver self-service forgot/reset via Resend, logged-in password change, and optional avatar on /campanha/perfil; register post-simplify engineering debts as RS+.
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { z } from 'zod'
|
|
import type { RefinementCtx } from 'zod'
|
|
|
|
export const CAMPAIGN_PASSWORD_RESET_TOKEN_MIN_LENGTH = 20
|
|
|
|
const passwordSchema = z
|
|
.string()
|
|
.min(8, 'A senha deve ter pelo menos 8 caracteres.')
|
|
.max(128, 'A senha deve ter no máximo 128 caracteres.')
|
|
|
|
const refineMatchingPasswords = (
|
|
data: { password: string; passwordConfirmation: string },
|
|
context: RefinementCtx,
|
|
) => {
|
|
if (data.password !== data.passwordConfirmation) {
|
|
context.addIssue({
|
|
code: 'custom',
|
|
message: 'As senhas não coincidem.',
|
|
path: ['passwordConfirmation'],
|
|
})
|
|
}
|
|
}
|
|
|
|
export const campaignPasswordResetRequestSchema = z.object({
|
|
email: z.email('Informe um e-mail válido.').trim(),
|
|
})
|
|
|
|
export const campaignPasswordResetSchema = z
|
|
.object({
|
|
token: z.string().min(CAMPAIGN_PASSWORD_RESET_TOKEN_MIN_LENGTH).max(256),
|
|
password: passwordSchema,
|
|
passwordConfirmation: passwordSchema,
|
|
})
|
|
.superRefine(refineMatchingPasswords)
|
|
|
|
export const campaignChangePasswordSchema = z
|
|
.object({
|
|
currentPassword: z.string().min(1, 'Informe a senha atual.'),
|
|
password: passwordSchema,
|
|
passwordConfirmation: passwordSchema,
|
|
})
|
|
.superRefine((data, context) => {
|
|
refineMatchingPasswords(data, context)
|
|
if (data.currentPassword === data.password) {
|
|
context.addIssue({
|
|
code: 'custom',
|
|
message: 'A nova senha deve ser diferente da atual.',
|
|
path: ['password'],
|
|
})
|
|
}
|
|
})
|