mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
## Description Add support to login with passkeys. Passkeys can be added via the user security settings page. Note: Currently left out adding the type of authentication method for the 'user security audit logs' because we're using the `signIn` next-auth event which doesn't appear to provide the context. Will look into it at another time. ## Changes Made - Add passkeys to login - Add passkeys feature flag - Add page to manage passkeys - Add audit logs relating to passkeys - Updated prisma schema to support passkeys & anonymous verification tokens ## Testing Performed To be done. MacOS: - Safari ✅ - Chrome ✅ - Firefox ✅ Windows: - Chrome [Untested] - Firefox [Untested] Linux: - Chrome [Untested] - Firefox [Untested] iOS: - Safari ✅ ## Checklist <!--- Please check the boxes that apply to this pull request. --> <!--- You can add or remove items as needed. --> - [X] I have tested these changes locally and they work as expected. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced Passkey authentication, including creation, sign-in, and management of passkeys. - Added a Passkeys section in Security Settings for managing user passkeys. - Implemented UI updates for Passkey authentication, including a new dialog for creating passkeys and a data table for managing them. - Enhanced security settings with server-side feature flags to conditionally display new security features. - **Bug Fixes** - Improved UI consistency in the Settings Security Activity Page. - Updated button styling in the 2FA Recovery Codes component for better visibility. - **Refactor** - Streamlined authentication options to include WebAuthn credentials provider. - **Chores** - Updated database schema to support passkeys and related functionality. - Added new audit log types for passkey-related activities. - Enhanced server-only authentication utilities for passkey registration and management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
64 lines
2.0 KiB
TypeScript
64 lines
2.0 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 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 });
|