1 import type { FormikErrors } from 'formik';
2 import { c } from 'ttag';
4 import { parseOTPValue } from '@proton/pass/lib/otp/otp';
5 import type { LoginItemFormValues } from '@proton/pass/types';
7 import { validateAliasForm } from './alias';
8 import { validateExtraFields } from './extra-field';
9 import { validateItemErrors } from './item';
10 import { validateUrl, validateUrls } from './url';
12 const validateTotpUri = (values: LoginItemFormValues) => {
14 const normalized = parseOTPValue(values.totpUri);
15 if (!normalized) return { totpUri: c('Validation').t`OTP secret or URI is invalid` };
21 type ValidateLoginForm = {
22 values: LoginItemFormValues;
23 shouldValidateEmail?: boolean;
26 export const validateLoginForm = ({ values }: ValidateLoginForm): FormikErrors<LoginItemFormValues> => {
27 const errors: FormikErrors<LoginItemFormValues> = validateItemErrors(values);
28 const urlError = validateUrl(values);
29 const urlsErrors = validateUrls(values);
30 const totpUriErrors = validateTotpUri(values);
31 const aliasErrors = values.withAlias && validateAliasForm(values);
32 const extraFieldsErrors = validateExtraFields(values);