Obtaining a token
A token is issued in the response body of any of the three auth endpoints:| Endpoint | Description |
|---|---|
POST /auth/google | Sign in or register via Google OAuth |
POST /auth/signup-email | Register with email and password |
POST /auth/login-email | Sign in with email and password |
Sending the token
Include the token in thex-access'courser-auth-token header of every authenticated request.
Token format and expiry
- Tokens are signed JWTs using the server’s
JWT_PRIVATE_KEYenvironment variable. - Each token encodes the user’s internal
_id. - Tokens expire after 1000 days.
User ID derivation
Courser does not store Firebase UIDs directly. Instead, the user’s internal_id is derived by taking the SHA-256 hash of the Firebase UID (or Google idToken) and truncating it to the first 24 hex characters.
Protected endpoints
Endpoints that require authentication run theisLoggedIn middleware, which:
Extract the token
Reads the value of the
x-access'courser-auth-token request header. Returns 401 if the header is absent.Verify the token
Verifies the JWT signature using
JWT_PRIVATE_KEY. Returns 401 if the token is invalid or expired.Look up the user
Queries MongoDB for the user whose
_id matches the decoded token payload. Returns 401 if no user is found.401 error responses
Authenticated endpoints return401 with one of the following string bodies when authentication fails:
| Body | Cause |
|---|---|
"not-logged-in" | Header is missing |
"no user found" | Token is valid but the user no longer exists in the database |
"ERROR" | Token verification failed (invalid signature or expired) |