added 2FA

This commit is contained in:
2024-04-26 22:16:21 +03:00
parent 53cadc289a
commit f17a002ac6
38 changed files with 1036 additions and 414 deletions

View File

@@ -1,5 +1,8 @@
import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH, PASSWORD_STRENGTH_ACME } from '@/config/validation'
import { object, string } from 'zod'
import { object, optional, string } from 'zod'
const _2FA_CODE_LENGTH = 6
const _2FA_CODE_REGEX = /^\d{6}$/
// all translations is implemented in '@/components/ui/form' via TranslateClientFragment
@@ -7,6 +10,7 @@ const minPasswordMessage = JSON.stringify(['schema.password.length.min', { min:
const maxPasswordMessage = JSON.stringify(['schema.password.length.max', { max: MAX_PASSWORD_LENGTH }])
const maxPasswordStrength = JSON.stringify(
['schema.password.strength.acme', { min: MIN_PASSWORD_LENGTH, max: MAX_PASSWORD_LENGTH }])
const regexCodeMessage = JSON.stringify(['schema.two_factor.length', { length: _2FA_CODE_LENGTH }])
const email = string().trim().toLowerCase().email({ message: 'schema.email.required' })
const password = string().trim().regex(new RegExp(PASSWORD_STRENGTH_ACME, 'mg'),
@@ -14,7 +18,13 @@ const password = string().trim().regex(new RegExp(PASSWORD_STRENGTH_ACME, 'mg'),
max(MAX_PASSWORD_LENGTH, { message: maxPasswordMessage })
export const LoginSchema = object({
email, password: string().trim().min(1, { message: 'schema.password.required' }),
email,
password: string().trim().min(1, { message: 'schema.password.required' }),
code: string({ message: regexCodeMessage }).
trim().
length(_2FA_CODE_LENGTH, { message: regexCodeMessage }).
regex(_2FA_CODE_REGEX, { message: regexCodeMessage }).
optional(),
})
export const RegisterSchema = object({