Implement a session-based authentication system supporting "generate", "renew" and "count" queries
Asked in the Coding stage. The task is open-ended and evaluates clean API design, boundary conditions, tests, and performance. Create a PostgreSQL function that handles all three operations using the supplied authentication tables.
operation, token, and active_sessions.token is populated for a successful generation or renewal, and otherwise is NULL.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique application user identifier |
| VARCHAR(255) | User email address |
| Column | Type | Description |
|---|---|---|
| session_idPK | BIGINT | Unique session identifier |
| token | VARCHAR(64) | Opaque authentication token |
| user_id | INTEGER | Referenced application user |
| issued_at | TIMESTAMPTZ | Session creation timestamp |
| expires_at | TIMESTAMPTZ | Timestamp after which the session is inactive |
| revoked_at | TIMESTAMPTZ | Revocation timestamp, or NULL when not revoked |