mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
## Description Add the following document action auth options: - 2FA - Passkey If the user does not have the required auth setup, we onboard them directly. ## Changes made Note: Added secondaryId to the VerificationToken schema ## Testing Performed Tested locally, pending preview tests ## Checklist - [X] I have tested these changes locally and they work as expected. - [X] I have added/updated tests that prove the effectiveness of these changes. - [X] I have followed the project's coding style guidelines. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced components for 2FA, account, and passkey authentication during document signing. - Added "Require passkey" option to document settings and signer authentication settings. - Enhanced form submission and loading states for improved user experience. - **Refactor** - Optimized authentication components to efficiently support multiple authentication methods. - **Chores** - Updated and renamed functions and components for clarity and consistency across the authentication system. - Refined sorting options and database schema to support new authentication features. - **Bug Fixes** - Adjusted SignInForm to verify browser support for WebAuthn before proceeding. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { ZBaseTableSearchParamsSchema } from '@documenso/lib/types/search-params';
|
|
import { ZRegistrationResponseJSONSchema } from '@documenso/lib/types/webauthn';
|
|
|
|
export const ZCurrentPasswordSchema = z
|
|
.string()
|
|
.min(6, { message: 'Must be at least 6 characters in length' })
|
|
.max(72);
|
|
|
|
export const ZPasswordSchema = z
|
|
.string()
|
|
.regex(new RegExp('.*[A-Z].*'), { message: 'One uppercase character' })
|
|
.regex(new RegExp('.*[a-z].*'), { message: 'One lowercase character' })
|
|
.regex(new RegExp('.*\\d.*'), { message: 'One number' })
|
|
.regex(new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'), {
|
|
message: 'One special character is required',
|
|
})
|
|
.min(8, { message: 'Must be at least 8 characters in length' })
|
|
.max(72, { message: 'Cannot be more than 72 characters in length' });
|
|
|
|
export const ZSignUpMutationSchema = z.object({
|
|
name: z.string().min(1),
|
|
email: z.string().email(),
|
|
password: ZPasswordSchema,
|
|
signature: z.string().min(1, { message: 'A signature is required.' }),
|
|
url: z
|
|
.string()
|
|
.trim()
|
|
.toLowerCase()
|
|
.min(1)
|
|
.regex(/^[a-z0-9-]+$/, {
|
|
message: 'Username can only container alphanumeric characters and dashes.',
|
|
})
|
|
.optional(),
|
|
});
|
|
|
|
export const ZCreatePasskeyMutationSchema = z.object({
|
|
passkeyName: z.string().trim().min(1),
|
|
verificationResponse: ZRegistrationResponseJSONSchema,
|
|
});
|
|
|
|
export const ZCreatePasskeyAuthenticationOptionsMutationSchema = z
|
|
.object({
|
|
preferredPasskeyId: z.string().optional(),
|
|
})
|
|
.optional();
|
|
|
|
export const ZDeletePasskeyMutationSchema = z.object({
|
|
passkeyId: z.string().trim().min(1),
|
|
});
|
|
|
|
export const ZUpdatePasskeyMutationSchema = z.object({
|
|
passkeyId: z.string().trim().min(1),
|
|
name: z.string().trim().min(1),
|
|
});
|
|
|
|
export const ZFindPasskeysQuerySchema = ZBaseTableSearchParamsSchema.extend({
|
|
orderBy: z
|
|
.object({
|
|
column: z.enum(['createdAt', 'updatedAt', 'name']),
|
|
direction: z.enum(['asc', 'desc']),
|
|
})
|
|
.optional(),
|
|
});
|
|
|
|
export type TSignUpMutationSchema = z.infer<typeof ZSignUpMutationSchema>;
|
|
|
|
export const ZVerifyPasswordMutationSchema = ZSignUpMutationSchema.pick({ password: true });
|