Appearance
Authentication Data Models
Detailed schema documentation for authentication-related database tables.
User Table
Primary user account table managed by Better Auth.
sql
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255),
email VARCHAR(255) NOT NULL UNIQUE,
email_verified BOOLEAN DEFAULT false,
image TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);Columns
id: UUID primary key for securityname: User's display name (optional)email: Login email address (unique)email_verified: Email verification statusimage: Profile image URL (optional)created_at: Account creation timestampupdated_at: Last profile update
Indexes
- Primary key on
id - Unique index on
email - Index on
created_atfor sorting
Session Table
Active user sessions with organization context.
sql
CREATE TABLE sessions (
id VARCHAR(255) PRIMARY KEY,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
expires_at TIMESTAMP NOT NULL,
ip_address VARCHAR(45),
user_agent TEXT,
active_organization_id UUID REFERENCES organizations(id) ON DELETE SET NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);Columns
id: Session token (opaque string)user_id: Reference to userexpires_at: Session expiration timeip_address: Client IP for securityuser_agent: Browser/client infoactive_organization_id: Current workspace contextcreated_at: Session start timeupdated_at: Last activity time
Indexes
- Primary key on
id - Foreign key index on
user_id - Index on
expires_atfor cleanup - Index on
active_organization_id
Account Table
OAuth provider accounts for future social login.
sql
CREATE TABLE accounts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
provider VARCHAR(255) NOT NULL,
provider_account_id VARCHAR(255) NOT NULL,
access_token TEXT,
refresh_token TEXT,
expires_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
UNIQUE(provider, provider_account_id)
);Columns
id: Account record IDuser_id: Reference to userprovider: OAuth provider name (google, github, etc.)provider_account_id: User ID from provideraccess_token: OAuth access token (encrypted)refresh_token: OAuth refresh token (encrypted)expires_at: Token expirationcreated_at: Account link timeupdated_at: Last token refresh
Indexes
- Primary key on
id - Foreign key index on
user_id - Unique composite index on
(provider, provider_account_id)
Verification Table
Email verification and password reset tokens.
sql
CREATE TABLE verifications (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
identifier VARCHAR(255) NOT NULL,
value VARCHAR(255) NOT NULL,
expires_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);Columns
id: Verification record IDidentifier: Email or user IDvalue: Verification token (hashed)expires_at: Token expirationcreated_at: Token generation timeupdated_at: Last update
Indexes
- Primary key on
id - Index on
identifier - Index on
expires_atfor cleanup
Password Table
Separate password storage for Better Auth.
sql
CREATE TABLE passwords (
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);Columns
user_id: Reference to user (primary key)hash: Argon2 password hashcreated_at: Password set timeupdated_at: Last password change
Indexes
- Primary key on
user_id
Security Implementation
Password Storage
- Passwords are hashed using Argon2 (configured in
config/hash.ts) - Managed by Better Auth's password table
Session Management
- Sessions stored in database with expiration timestamps
- Session tokens managed by Better Auth
- Active organization context tracked per session