SmartfolioBackend / docs /schema-auth.sql
mahrooshishaq
new commit by Mahroosh
9a951d7
Raw History Blame Contribute Delete
2.98 kB
-- =============================================================
-- MODULE: Auth / Users
-- File: docs/schema-auth.sql
-- Managed by: TypeORM (synchronize: true in development)
-- =============================================================
-- -----------------------------------------------------------
-- ENUMS
-- -----------------------------------------------------------
-- No dedicated enums in auth module
-- (Enums live in the onboarding module and are referenced here via FK)
-- -----------------------------------------------------------
-- TABLE: user
-- Entity: src/modules/users/user.entity.ts
-- Description: Core identity record for every registered user.
-- -----------------------------------------------------------
CREATE TABLE "user" (
-- Primary key
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Identity
email VARCHAR NOT NULL UNIQUE,
password VARCHAR, -- NULL for Google OAuth users
google_id VARCHAR UNIQUE, -- NULL for email/password users
name VARCHAR NOT NULL,
-- Email verification
is_verified BOOLEAN NOT NULL DEFAULT FALSE,
otp_hash VARCHAR, -- bcrypt hash of the 6-digit OTP
otp_expiry TIMESTAMPTZ,
-- Session / refresh tokens
refresh_token_hash TEXT, -- bcrypt hash of refresh JWT
refresh_token_issued_at TIMESTAMP,
is_loggedin BOOLEAN NOT NULL DEFAULT FALSE,
-- Password reset
reset_token_hash TEXT,
reset_token_expiry TIMESTAMP
);
-- Indexes
CREATE INDEX idx_user_email ON "user" (email);
CREATE INDEX idx_user_google ON "user" (google_id);
-- -----------------------------------------------------------
-- VARIABLE REFERENCE
-- -----------------------------------------------------------
-- id β†’ UUID, primary key, used in all FK relations
-- email β†’ Used for login, OTP sending, uniqueness check
-- password β†’ Bcrypt hashed; NULL when registered via Google
-- google_id β†’ OAuth2 Google sub claim; NULL for email users
-- name β†’ Display name shown in UI and auth/me response
-- is_verified β†’ Must be TRUE before JWT tokens are issued
-- otp_hash β†’ Hashed 6-digit code; checked at POST /auth/verify-otp
-- otp_expiry β†’ 10-minute TTL; checked at verify-otp endpoint
-- refresh_token_hash β†’ Stored so refresh tokens can be invalidated on logout
-- refresh_token_issued_at β†’ Used to detect refresh token reuse attacks
-- is_loggedin β†’ Set to FALSE on POST /auth/logout
-- reset_token_hash β†’ Hashed token sent via email for password reset
-- reset_token_expiry β†’ 1-hour TTL for password reset links