mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +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 -->
121 lines
3.5 KiB
TypeScript
121 lines
3.5 KiB
TypeScript
'use client';
|
|
|
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
|
|
import { ZBaseTableSearchParamsSchema } from '@documenso/lib/types/search-params';
|
|
import { trpc } from '@documenso/trpc/react';
|
|
import { DataTable } from '@documenso/ui/primitives/data-table';
|
|
import { DataTablePagination } from '@documenso/ui/primitives/data-table-pagination';
|
|
import { Skeleton } from '@documenso/ui/primitives/skeleton';
|
|
import { TableCell } from '@documenso/ui/primitives/table';
|
|
|
|
import { UserPasskeysDataTableActions } from './user-passkeys-data-table-actions';
|
|
|
|
export const UserPasskeysDataTable = () => {
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
const updateSearchParams = useUpdateSearchParams();
|
|
|
|
const parsedSearchParams = ZBaseTableSearchParamsSchema.parse(
|
|
Object.fromEntries(searchParams ?? []),
|
|
);
|
|
|
|
const { data, isLoading, isInitialLoading, isLoadingError } = trpc.auth.findPasskeys.useQuery(
|
|
{
|
|
page: parsedSearchParams.page,
|
|
perPage: parsedSearchParams.perPage,
|
|
},
|
|
{
|
|
keepPreviousData: true,
|
|
},
|
|
);
|
|
|
|
const onPaginationChange = (page: number, perPage: number) => {
|
|
updateSearchParams({
|
|
page,
|
|
perPage,
|
|
});
|
|
};
|
|
|
|
const results = data ?? {
|
|
data: [],
|
|
perPage: 10,
|
|
currentPage: 1,
|
|
totalPages: 1,
|
|
};
|
|
|
|
return (
|
|
<DataTable
|
|
columns={[
|
|
{
|
|
header: 'Name',
|
|
accessorKey: 'name',
|
|
},
|
|
{
|
|
header: 'Created',
|
|
accessorKey: 'createdAt',
|
|
cell: ({ row }) => DateTime.fromJSDate(row.original.createdAt).toRelative(),
|
|
},
|
|
|
|
{
|
|
header: 'Last used',
|
|
accessorKey: 'updatedAt',
|
|
cell: ({ row }) =>
|
|
row.original.lastUsedAt
|
|
? DateTime.fromJSDate(row.original.lastUsedAt).toRelative()
|
|
: 'Never',
|
|
},
|
|
{
|
|
id: 'actions',
|
|
cell: ({ row }) => (
|
|
<UserPasskeysDataTableActions
|
|
className="justify-end"
|
|
passkeyId={row.original.id}
|
|
passkeyName={row.original.name}
|
|
/>
|
|
),
|
|
},
|
|
]}
|
|
data={results.data}
|
|
perPage={results.perPage}
|
|
currentPage={results.currentPage}
|
|
totalPages={results.totalPages}
|
|
onPaginationChange={onPaginationChange}
|
|
hasFilters={parsedSearchParams.page !== undefined || parsedSearchParams.perPage !== undefined}
|
|
onClearFilters={() => router.push(pathname ?? '/')}
|
|
error={{
|
|
enable: isLoadingError,
|
|
}}
|
|
skeleton={{
|
|
enable: isLoading && isInitialLoading,
|
|
rows: 3,
|
|
component: (
|
|
<>
|
|
<TableCell>
|
|
<Skeleton className="h-4 w-20 rounded-full" />
|
|
</TableCell>
|
|
<TableCell>
|
|
<Skeleton className="h-4 w-12 rounded-full" />
|
|
</TableCell>
|
|
<TableCell>
|
|
<Skeleton className="h-4 w-12 rounded-full" />
|
|
</TableCell>
|
|
<TableCell>
|
|
<div className="flex flex-row space-x-2">
|
|
<Skeleton className="h-8 w-16 rounded" />
|
|
<Skeleton className="h-8 w-16 rounded" />
|
|
</div>
|
|
</TableCell>
|
|
</>
|
|
),
|
|
}}
|
|
>
|
|
{(table) => <DataTablePagination table={table} />}
|
|
</DataTable>
|
|
);
|
|
};
|