Authentication & Sessions
Deep dive into ForkFit session-based authentication model, token structure, and OTP validation.
Authentication & Sessions
ForkFit employs a secure, stateless bearer-token session model. Upon signing in, client apps receive an access token that must be presented in the Authorization header of all protected requests.
Authorization Header
All protected resources expect an Authorization header in the following format:
Authorization: Bearer <your_session_token>Missing or Invalid Token
If the token is missing, expired, or revoked, the server replies with a 401 Unauthorized status.
Token Lifecycle
- Generation: Created during
/auth/signinor successful OAuth callbacks. - TTL (Time to Live): Configured via the
SESSION_TTL_SECONDSenvironment variable (defaults to 30 days). - Storage: Access tokens are stored on the server as active sessions in the
user_sessionsdatabase table, enabling real-time audits and revocation. - Revocation: A user can delete specific session IDs, or revoke all active sessions (
/auth/signout-all).
One-Time Passwords (OTP)
Certain operations (such as email verification and resetting passwords) require a temporary 6-digit verification code:
- OTP Lifespan: Configured via
OTP_TTL_SECONDS(defaults to 10 minutes). - Max Attempts: Users are allowed up to 5 attempts to input the correct OTP before the code is permanently invalidated.