feat(auth): add passkey sign-in and management
Sign in with Face ID, Touch ID, Windows Hello or a security key, keeping email + password as the primary method. - API: BetterAuth passkey plugin deriving rpID/origin from WEB_APP_URL (the browser origin), with residentKey "required" because sign-in is username-less. New Passkey model mapped to the passkeys table. - Web: conditional UI in the email field plus an explicit "Entrar con passkey" button; cancelled ceremonies are ignored. - Settings: create, rename and delete passkeys with TanStack Query. - Pin @better-auth/passkey to 1.7.7: its peers lock better-call, so newer versions break the API.
This commit is contained in:
26
AGENTS.md
26
AGENTS.md
@@ -6,9 +6,10 @@ Scaffold is in place and verified: Turborepo monorepo with `apps/api`, `apps/web
|
||||
Biome as the only JS/TS tool and the text Bun lockfile committed. It is deployed with Docker Compose on
|
||||
Dokploy (`docker-compose.yml`); there is no hosted CI.
|
||||
|
||||
Not done yet: product features are just starting (sign-up, password recovery with an emailed OTP, shopping lists, list items and invitations exist;
|
||||
there is no Google login and no email verification; the `voice` module splits dictated text with Groq, or Gemma 4
|
||||
through the Gemini API when Groq is not configured). The `health` module is the reference example.
|
||||
Not done yet: product features are just starting (sign-up, password recovery with an emailed OTP, passkeys,
|
||||
shopping lists, list items and invitations exist; there is no Google login and no email verification; the
|
||||
`voice` module splits dictated text with Groq, or Gemma 4 through the Gemini API when Groq is not configured).
|
||||
The `health` module is the reference example.
|
||||
|
||||
## Stack (source of truth: `STACK.md`)
|
||||
|
||||
@@ -100,7 +101,8 @@ Run from the repo root. Verification order is `build`, then `lint` → `typechec
|
||||
`apps/web/nginx.conf`, which also proxies `/api/*` to `http://superlist-api:4100` (re-resolved through
|
||||
Docker's DNS, so API redeploys don't leave nginx on a stale IP). Required env vars are interpolated
|
||||
by Compose (`DATABASE_URL`, `BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`, `CORS_ORIGIN`, `WEB_APP_URL`); set them
|
||||
in Dokploy. The dictation variables (`GROQ_API_KEY`, `GROQ_MODEL`, `GROQ_TIMEOUT_MS`, `GEMINI_API_KEY`, `GEMINI_MODEL`,
|
||||
in Dokploy. `WEB_APP_URL` is not only used for email links: it is also the WebAuthn relying-party origin, so
|
||||
it must be the exact public URL of the web app. The dictation variables (`GROQ_API_KEY`, `GROQ_MODEL`, `GROQ_TIMEOUT_MS`, `GEMINI_API_KEY`, `GEMINI_MODEL`,
|
||||
`GEMINI_TIMEOUT_MS`) are optional (Groq wins when its key is set) and
|
||||
backend-only — never give them a `VITE_` prefix, or Vite would ship the key in the browser bundle. There is no hosted CI.
|
||||
- Generated files are gitignored and must never be edited by hand: `apps/web/src/routeTree.gen.ts`,
|
||||
@@ -208,6 +210,15 @@ export class CreateAlert {
|
||||
plugin (6-digit code, 10 minutes, hashed in `verifications`): the web `/forgot-password` route calls
|
||||
`emailOtp.requestPasswordReset` / `emailOtp.resetPassword`, and the code is sent with `sendEmail`
|
||||
(`lib/mailer.ts`, template in `lib/emails/password-reset.ts`). Without `RESEND_API_KEY` the code is logged.
|
||||
- **Passkeys**: the separate `@better-auth/passkey` package (installed in both apps) adds WebAuthn sign-in.
|
||||
Pin it to the exact same version as `better-auth` (currently `1.7.7`): its peer dependencies
|
||||
(`better-call`, `@better-auth/core`) are version-locked, so a newer passkey package breaks the API.
|
||||
`lib/passkey-config.ts` derives `rpID` and `origin` from `WEB_APP_URL`, **not** from `BETTER_AUTH_URL`:
|
||||
WebAuthn runs in the browser, where the web origin is `:7153` in dev and the public web domain in
|
||||
production. Sign-in is username-less, so the plugin is configured with `residentKey: 'required'`.
|
||||
Passkeys are bound to the domain: those registered on `localhost` do not work in production (and vice
|
||||
versa). The `Passkey`/`passkeys` Prisma model is mapped by hand like the rest of the schema; the plugin
|
||||
also runs `prisma migrate deploy` before starting in production.
|
||||
- **Prisma 7**: the generator is `prisma-client` and writes to `apps/api/src/generated/prisma` (gitignored), so
|
||||
import it as `@/generated/prisma/client` — never `@prisma/client` directly. The client uses the
|
||||
`@prisma/adapter-pg` adapter with `DATABASE_URL` and is exported as `prisma` (plus the `Database` type) from
|
||||
@@ -216,9 +227,10 @@ export class CreateAlert {
|
||||
the generated migration under `apps/api/prisma/migrations` — never edit migration files by hand. The
|
||||
datasource has no `url` in the schema: it comes from `prisma.config.ts` (`env('DATABASE_URL')`). For
|
||||
production, `apps/api` also has `db:deploy` (`prisma migrate deploy`), which is not wired to a turbo task yet.
|
||||
- The BetterAuth models (`User`, `Session`, `Account`, `Verification`) are already in the schema and follow the
|
||||
naming convention above (`users`, `sessions`, `accounts`, `verifications` with snake_case columns); regenerate
|
||||
them with the BetterAuth CLI rather than by hand if the auth config changes, then re-apply the mapping.
|
||||
- The BetterAuth models (`User`, `Session`, `Account`, `Verification`, `Passkey`) are already in the schema and
|
||||
follow the naming convention above (`users`, `sessions`, `accounts`, `verifications`, `passkeys` with
|
||||
snake_case columns); regenerate them with the BetterAuth CLI rather than by hand if the auth config changes,
|
||||
then re-apply the mapping. `Passkey` comes from the `@better-auth/passkey` plugin, not the core CLI.
|
||||
|
||||
## Shared package (`@superlist/shared`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user