Overview
BeatPass uses Laravel Sanctum for SPA (single-page application) authentication. This is a cookie-based session authentication system designed for first-party frontend applications.Authentication Model
BeatPass uses stateful SPA authentication:Cookie Sessions
All auth uses secure, HttpOnly session cookies
CSRF Required
State-changing requests require CSRF tokens
No API Tokens
Personal access tokens are not issued
First-Party Only
Third-party integrations not supported
SPA Authentication Flow
The BeatPass frontend authenticates using Sanctum’s SPA authentication:1
Get CSRF Cookie
Before login, request a CSRF cookie:This sets the
XSRF-TOKEN cookie.2
Submit Login
POST credentials with the CSRF token:
3
Handle 2FA (if enabled)
If 2FA is enabled, you’ll receive a
two_factor: true response.
Submit the TOTP code:4
Session Established
On success, a session cookie is set. All subsequent requests include this cookie automatically.
CSRF Protection
How CSRF Works
- Cookie: Sanctum sets an
XSRF-TOKENcookie (URL-encoded) - Header: Include the decoded token in
X-XSRF-TOKENheader - Verification: Laravel verifies the header matches the cookie
JavaScript Example
Axios Configuration
Stateful Domains
Cookie-based authentication is only available from approved BeatPass domains. Requests from other origins will not receive authenticated sessions.This is a first-party API. Cross-origin requests from third-party domains are not supported.
Optional vs Required Auth
Optional Auth Endpoints
Many endpoints work without authentication but return enhanced data when authenticated:Required Auth Endpoints
These endpoints require an authenticated session:Two-Factor Authentication
When 2FA is enabled, the login flow requires an additional step:Initial Login Response (2FA Required)
Submit 2FA Code
Session Security
Best Practices
HTTPS Only
HTTPS Only
All API requests must use HTTPS. Cookies sent over HTTP can be intercepted.
Cookie Security
Cookie Security
Session Management
Session Management
Users can log out other sessions from Account Settings → Active Sessions.
Session Expiration
Session Expiration
Web sessions expire based on server configuration. Re-authenticate when sessions expire.
Logging Out
Users can log out of the current session, or log out all other sessions from the Active sessions panel in Account Settings.Authentication Errors
401 Unauthenticated
401 Unauthenticated
401 Session missing, invalid, or expired.Solution: Re-authenticate by calling
/sanctum/csrf-cookie then /login.403 Forbidden
403 Forbidden
403 User lacks permission for this resource.Solution: Check that your account has the required role or ownership.
419 Session Expired
419 Session Expired
419 CSRF token mismatch or session timeout.Solution: Refresh CSRF token by calling
/sanctum/csrf-cookie again.Social Login
BeatPass supports social authentication providers:Available
Available
Available
Social logins create a BeatPass account and session automatically. You can link additional providers in Account Settings.