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:
@@ -0,0 +1,25 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "passkeys" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT,
|
||||
"public_key" TEXT NOT NULL,
|
||||
"user_id" TEXT NOT NULL,
|
||||
"credential_id" TEXT NOT NULL,
|
||||
"counter" INTEGER NOT NULL,
|
||||
"device_type" TEXT NOT NULL,
|
||||
"backed_up" BOOLEAN NOT NULL,
|
||||
"transports" TEXT,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"aaguid" TEXT,
|
||||
|
||||
CONSTRAINT "passkeys_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "passkeys_user_id_idx" ON "passkeys"("user_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "passkeys_credential_id_idx" ON "passkeys"("credential_id");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "passkeys" ADD CONSTRAINT "passkeys_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -34,6 +34,7 @@ model User {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
sessions Session[]
|
||||
accounts Account[]
|
||||
passkeys Passkey[]
|
||||
ownedLists ShoppingList[] @relation("ListOwner")
|
||||
memberships ShoppingListMember[]
|
||||
invitations ShoppingListInvitation[] @relation("InvitedBy")
|
||||
@@ -90,6 +91,29 @@ model Verification {
|
||||
@@map("verifications")
|
||||
}
|
||||
|
||||
// WebAuthn credentials registered through the BetterAuth passkey plugin.
|
||||
// `credentialID` is the raw credential id and `publicKey` the stored public key;
|
||||
// the plugin reads and writes these rows directly, so keep the column names it
|
||||
// expects (mapped to snake_case like the rest of the schema).
|
||||
model Passkey {
|
||||
id String @id
|
||||
name String?
|
||||
publicKey String @map("public_key")
|
||||
userId String @map("user_id")
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
credentialID String @map("credential_id")
|
||||
counter Int
|
||||
deviceType String @map("device_type")
|
||||
backedUp Boolean @map("backed_up")
|
||||
transports String?
|
||||
createdAt DateTime? @default(now()) @map("created_at")
|
||||
aaguid String?
|
||||
|
||||
@@index([userId])
|
||||
@@index([credentialID])
|
||||
@@map("passkeys")
|
||||
}
|
||||
|
||||
// --- Domain models ----------------------------------------------------------
|
||||
|
||||
/// A collaborative shopping list. Membership (and therefore access) lives in
|
||||
|
||||
Reference in New Issue
Block a user