user_sessions table
The user_sessions table in the Reddit Clone Database Schema schema has 9 columns, keyed by id, with 2 foreign keys to users and user_devices.
Only the hash of the token is stored. Revocation is a timestamp rather than a delete, so a forced logout leaves evidence and the session list can show what was ended and when.
Columns (9)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| user_id | uuid | not null, references users.id | |
| token_hash | varchar(255) | unique, not null | |
| device_id | uuid | references user_devices.id | |
| ip_address | varchar(45) | ||
| user_agent | varchar(500) | ||
| created_at | timestamptz | not null | |
| expires_at | timestamptz | not null | |
| revoked_at | timestamptz |
Indexes (1)
(user_id, expires_at)
Relationships
user_sessions.user_idreferencesusers.iduser_sessions.device_idreferencesuser_devices.id