feat(story-1.4): add session-based authentication with login/logout

This commit is contained in:
Michael committed 2026-02-04 14:44:48 +01:00
1 parent e186a4dd87
commit d67e169a43
8 files changed
+446 -13

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
-- Migration: 002_create_sessions
-- Description: Create the sessions table for stateful authentication
CREATE TABLE IF NOT EXISTS sessions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
token VARCHAR(64) NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
user_agent TEXT,
ip_address VARCHAR(45)
);
-- Index for token lookup (authentication)
CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions(token);
-- Index for user_id (session cleanup)
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
-- Index for expiration cleanup
CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON sessions(expires_at);