UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

187 lines (186 loc) 4.81 kB
'use client'; import { useFormField as o, useFormContext as a, FormWrapper as s } from "./form-wrapper.js"; import { FormContext as _ } from "./form-wrapper.js"; import { PasswordConfirmationField as n, PasswordField as d } from "./password-field.js"; import { EmailField as u } from "./email-field.js"; import { PhoneField as l } from "./phone-field.js"; import { VerificationCode as m } from "./verification-code.js"; import f, { useFieldError as c } from "./field-error.js"; import { FieldError as x } from "./field-error.js"; const i = { email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, phone: /^\+?[\d\s\-\(\)]+$/, password: { minLength: 8, maxLength: 128, requireUppercase: /[A-Z]/, requireLowercase: /[a-z]/, requireNumbers: /\d/, requireSpecialChars: /[!@#$%^&*(),.?":{}|<>_\-+=\[\]\\;'\/~`]/ }, verificationCode: { numeric: /^\d+$/, alphanumeric: /^[a-zA-Z0-9]+$/ } }, C = { isValidEmail: (e) => i.email.test(e), isValidPhone: (e) => i.phone.test(e), isStrongPassword: (e) => { const r = i.password; return e.length >= r.minLength && e.length <= r.maxLength && r.requireUppercase.test(e) && r.requireLowercase.test(e) && r.requireNumbers.test(e) && r.requireSpecialChars.test(e); }, isValidVerificationCode: (e, r, t = "numeric") => e.length !== r ? !1 : t === "numeric" ? i.verificationCode.numeric.test(e) : i.verificationCode.alphanumeric.test(e) }, E = { PasswordField: d, PasswordConfirmationField: n, EmailField: u, PhoneField: l, VerificationCode: m }, P = { FormWrapper: s, FieldError: f }, S = { useFormContext: a, useFormField: o, useFieldError: c }, p = { signIn: { fields: ["email", "password"], validation: { email: { required: !0, validateFormat: !0 }, password: { required: !0, minLength: 1 } } }, signUp: { fields: ["email", "password", "passwordConfirmation"], validation: { email: { required: !0, validateFormat: !0 }, password: { required: !0, showStrength: !0 }, passwordConfirmation: { required: !0, mustMatch: "password" } } }, resetPassword: { fields: ["email"], validation: { email: { required: !0, validateFormat: !0 } } }, changePassword: { fields: ["currentPassword", "newPassword", "confirmPassword"], validation: { currentPassword: { required: !0 }, newPassword: { required: !0, showStrength: !0 }, confirmPassword: { required: !0, mustMatch: "newPassword" } } }, verifyEmail: { fields: ["verificationCode"], validation: { verificationCode: { required: !0, length: 6, type: "numeric" } } }, verifyPhone: { fields: ["phone", "verificationCode"], validation: { phone: { required: !0, validateFormat: !0 }, verificationCode: { required: !0, length: 6, type: "numeric" } } }, setupMFA: { fields: ["verificationCode"], validation: { verificationCode: { required: !0, length: 6, type: "numeric" } } }, verifyMFA: { fields: ["verificationCode"], validation: { verificationCode: { required: !0, length: 6, type: "numeric" } } }, organizationInvite: { fields: ["email"], validation: { email: { required: !0, validateFormat: !0 } } } }; function R(e, r = {}) { const t = p[e]; return { ...t, ...r, validation: { ...t.validation, ...r.validation } }; } function y(e, r) { switch (r.type) { case "SET_VALUE": return { ...e, values: { ...e.values, [r.field]: r.value }, isDirty: !0, // Clear error when value changes errors: { ...e.errors, [r.field]: "" } }; case "SET_ERROR": return { ...e, errors: { ...e.errors, [r.field]: r.error || "" } }; case "SET_TOUCHED": return { ...e, touched: { ...e.touched, [r.field]: r.touched } }; case "SET_SUBMITTING": return { ...e, isSubmitting: r.isSubmitting }; case "RESET_FORM": return { values: r.initialValues || {}, errors: {}, touched: {}, isSubmitting: !1, isValid: !0, isDirty: !1 }; case "CLEAR_ERRORS": return { ...e, errors: {} }; default: return e; } } export { u as EmailField, x as FieldError, _ as FormContext, E as FormFields, S as FormHooks, p as FormPresets, P as FormUtilities, s as FormWrapper, n as PasswordConfirmationField, d as PasswordField, l as PhoneField, C as ValidationHelpers, i as ValidationRules, m as VerificationCode, R as buildForm, y as formReducer, c as useFieldError, a as useFormContext, o as useFormField }; //# sourceMappingURL=index.js.map