Skip to content

feat: add session token authentication - #13

Merged
vinimachadosantana merged 3 commits into
developfrom
feat/session-tokens
Aug 7, 2026
Merged

feat: add session token authentication#13
vinimachadosantana merged 3 commits into
developfrom
feat/session-tokens

Conversation

@vinimachadosantana

Copy link
Copy Markdown
Owner

What

Adds a Session model with secure tokens, an authentication concern reading the Authorization header, and login/logout endpoints.

Why

Database-backed bearer tokens over JWT: revocation is a delete, so banning a user or logging out everywhere takes effect immediately. The trade-off is a session lookup per request, which is acceptable at this scale and cheap to cache later.

How

  • Authentication is required by default so forgetting a check locks an endpoint rather than exposing it.
  • authenticate_by is constant-time, so response timing can't be used to discover which emails are registered.
  • Sessions record IP and user agent, giving an audit trail and the basis for a "log out other devices" feature later.
  • has_secure_token generates cryptographically random tokens.
  • A spec proves a revoked token is rejected immediately.

Testing

  • Login, logout, missing token, and revoked token all covered
  • Identical error message for unknown email and wrong password
  • RuboCop and Brakeman clean

@vinimachadosantana vinimachadosantana self-assigned this Aug 7, 2026
@vinimachadosantana
vinimachadosantana merged commit f43c499 into develop Aug 7, 2026
3 checks passed
@vinimachadosantana
vinimachadosantana deleted the feat/session-tokens branch August 7, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant