mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 11:33:07 +00:00
WebAuthn platform passkeys: opt-in enrollment after a password login, a password-less sign-in that mints the same 14-day campaign-token, and revocation from the profile. The session is minted through Payload's public pieces (checkLoginPermission, addSessionToUser, getFieldsToSign, jwtSign) inside a transaction with an advisory lock, so a passkey login neither bypasses a lockout nor evicts the account's other sessions. The rpID is derived from NEXT_PUBLIC_SITE_URL and resolves to null when the request host disagrees, so previews never offer a ceremony the browser would refuse.
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Biometric login credentials (WebAuthn passkeys)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import { isCampaignUser, isPayloadAdmin, payloadAdminOnly } from '@/utilities/access/shared'
|
|
import type { Access } from 'payload'
|
|
|
|
/**
|
|
* A passkey is a login factor, so it is strictly the owner's business: nobody
|
|
* on staff — coordinator included — reads or revokes another account's
|
|
* credentials. The row-level constraint (not a boolean) is what keeps a
|
|
* campaign JWT hitting `/api/campaignWebAuthnCredential` scoped to itself.
|
|
*/
|
|
export const canReadOwnWebAuthnCredentials: Access = ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
if (!isCampaignUser(req.user)) return false
|
|
|
|
return { user: { equals: req.user.id } }
|
|
}
|
|
|
|
export const canDeleteOwnWebAuthnCredentials: Access = canReadOwnWebAuthnCredentials
|
|
|
|
/**
|
|
* Enrollment and the sign-counter/`lastUsedAt` bump both run inside the
|
|
* ceremony's transaction with `overrideAccess: true`, after the server verified
|
|
* the attestation. Nothing else may write a credential: a client-shaped create
|
|
* would let a session register a public key the authenticator never signed.
|
|
*/
|
|
export const canWriteWebAuthnCredentials: Access = payloadAdminOnly
|