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.
210 lines
7.3 KiB
Plaintext
210 lines
7.3 KiB
Plaintext
// Prisma schema. Docs: https://pris.ly/d/prisma-schema
|
|
//
|
|
// Naming convention (see AGENTS.md): tables are plural snake_case
|
|
// (`shopping_lists`, `users`), columns are snake_case (`created_at`,
|
|
// `owner_id`) and enum types are snake_case (`list_role`), declared through
|
|
// `@@map` / `@map`. The Prisma *model* and *field* names stay PascalCase /
|
|
// camelCase because BetterAuth and the generated client address models by
|
|
// those names.
|
|
//
|
|
// After editing this file run `bun run db:migrate` (creates + applies a migration)
|
|
// and commit the generated migration under `prisma/migrations`.
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
}
|
|
|
|
// --- BetterAuth core models -------------------------------------------------
|
|
// Shape generated by `bunx @better-auth/cli generate`. Keep in sync with the
|
|
// fields the auth config expects, and keep the snake_case mapping below if you
|
|
// regenerate it.
|
|
|
|
model User {
|
|
id String @id
|
|
name String
|
|
email String
|
|
emailVerified Boolean @default(false) @map("email_verified")
|
|
image String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
sessions Session[]
|
|
accounts Account[]
|
|
passkeys Passkey[]
|
|
ownedLists ShoppingList[] @relation("ListOwner")
|
|
memberships ShoppingListMember[]
|
|
invitations ShoppingListInvitation[] @relation("InvitedBy")
|
|
|
|
@@unique([email])
|
|
@@map("users")
|
|
}
|
|
|
|
model Session {
|
|
id String @id
|
|
expiresAt DateTime @map("expires_at")
|
|
token String
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
ipAddress String? @map("ip_address")
|
|
userAgent String? @map("user_agent")
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([token])
|
|
@@index([userId])
|
|
@@map("sessions")
|
|
}
|
|
|
|
model Account {
|
|
id String @id
|
|
accountId String @map("account_id")
|
|
providerId String @map("provider_id")
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
accessToken String? @map("access_token")
|
|
refreshToken String? @map("refresh_token")
|
|
idToken String? @map("id_token")
|
|
accessTokenExpiresAt DateTime? @map("access_token_expires_at")
|
|
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
|
|
scope String?
|
|
password String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([userId])
|
|
@@map("accounts")
|
|
}
|
|
|
|
model Verification {
|
|
id String @id
|
|
identifier String
|
|
value String
|
|
expiresAt DateTime @map("expires_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([identifier])
|
|
@@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
|
|
/// `ShoppingListMember`, not in this table.
|
|
model ShoppingList {
|
|
id String @id @default(uuid())
|
|
name String
|
|
ownerId String @map("owner_id")
|
|
owner User @relation("ListOwner", fields: [ownerId], references: [id], onDelete: Cascade)
|
|
members ShoppingListMember[]
|
|
invitations ShoppingListInvitation[]
|
|
items ListItem[]
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([ownerId])
|
|
@@map("shopping_lists")
|
|
}
|
|
|
|
model ListItem {
|
|
id String @id @default(cuid())
|
|
shoppingListId String @map("shopping_list_id")
|
|
name String
|
|
completed Boolean @default(false)
|
|
boughtAt DateTime? @map("bought_at")
|
|
quantity String? @map("quantity")
|
|
notes String? @map("notes")
|
|
order Int @default(0) @map("order")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
shoppingList ShoppingList @relation(fields: [shoppingListId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([shoppingListId, order])
|
|
@@map("list_items")
|
|
}
|
|
|
|
enum ListRole {
|
|
owner
|
|
collaborator
|
|
|
|
@@map("list_role")
|
|
}
|
|
|
|
/// Join table between a user and a list. `isPrimary` is per user: each person
|
|
/// picks their own main list among the ones they belong to.
|
|
model ShoppingListMember {
|
|
id String @id @default(uuid())
|
|
listId String @map("list_id")
|
|
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
role ListRole @default(collaborator)
|
|
isPrimary Boolean @default(false) @map("is_primary")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@unique([listId, userId])
|
|
@@index([userId, isPrimary])
|
|
@@map("shopping_list_members")
|
|
}
|
|
|
|
enum InvitationStatus {
|
|
pending
|
|
accepted
|
|
revoked
|
|
expired
|
|
|
|
@@map("invitation_status")
|
|
}
|
|
|
|
/// Pending or historical invitation of an email address to a list. When the
|
|
/// email already belongs to a user the membership is created immediately and
|
|
/// this record is stored as `accepted` for history.
|
|
model ShoppingListInvitation {
|
|
id String @id @default(uuid())
|
|
listId String @map("list_id")
|
|
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
|
email String
|
|
token String
|
|
status InvitationStatus @default(pending)
|
|
invitedById String @map("invited_by_id")
|
|
invitedBy User @relation("InvitedBy", fields: [invitedById], references: [id], onDelete: Cascade)
|
|
expiresAt DateTime @map("expires_at")
|
|
acceptedAt DateTime? @map("accepted_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@unique([token])
|
|
@@index([listId, status])
|
|
@@index([email, status])
|
|
@@map("shopping_list_invitations")
|
|
}
|