feat(db): add Better Auth tables (Session, Account, Verification)
- User extended with emailVerified, name, image (Better Auth fields) - Session: signed session tokens with expiry, ip and user agent - Account: credential rows for email+password (provider 'credential') and OAuth providers (e.g. Google) — password hash stored on the credential row - Verification: single-use tokens for email verification, password reset, and magic links - Re-export new types from @ketopath/db Migration 20260429104721_add_auth_tables run against local Postgres. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e9f1a55a5b
commit
79d4943c00
3 files changed
+128
-6
No files matched your search
@@ -52,18 +52,76 @@ enum FastingProtocol {
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
role Role @default(USER)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
emailVerified Boolean @default(false) @map("email_verified")
|
||||
name String?
|
||||
image String?
|
||||
role Role @default(USER)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
profile Profile?
|
||||
preferences Preferences?
|
||||
sessions Session[]
|
||||
accounts Account[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
// Better Auth — sessione utente firmata.
|
||||
model Session {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
token String @unique
|
||||
expiresAt DateTime @map("expires_at")
|
||||
ipAddress String? @map("ip_address")
|
||||
userAgent String? @map("user_agent")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("sessions")
|
||||
}
|
||||
|
||||
// Better Auth — credenziali (email+password) o account OAuth.
|
||||
// Per email+password il provider è 'credential' e la password (hash scrypt)
|
||||
// è salvata nel campo `password`.
|
||||
model Account {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
accountId String @map("account_id")
|
||||
providerId String @map("provider_id")
|
||||
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")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([providerId, accountId])
|
||||
@@map("accounts")
|
||||
}
|
||||
|
||||
// Better Auth — token monouso (email verification, password reset, magic link).
|
||||
model Verification {
|
||||
id String @id @default(cuid())
|
||||
identifier String
|
||||
value String
|
||||
expiresAt DateTime @map("expires_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@unique([identifier, value])
|
||||
@@map("verifications")
|
||||
}
|
||||
|
||||
model Profile {
|
||||
id String @id @default(cuid())
|
||||
userId String @unique @map("user_id")
|
||||
|
||||
Reference in new issue
Block a user