Sign in and obtain a token
Send aPOST request to /api/auth/login with your email and password. The response includes an accessToken and a refreshToken.
Your
@calpoly.edu email address.Your account password.
Use the token
Include theaccessToken in the Authorization header as a Bearer token on every protected request.
Token refresh
Access tokens expire. When a request returns HTTP 401, use therefreshToken to obtain a new session, then retry the original request.
The frontend authedFetch helper in lib/api.ts does this automatically:
- Attach the current
accessTokenand make the request. - If the response is
401, callrefreshSession()(which calls Supabase with the storedrefreshToken). - If a new
accessTokenis returned, retry the original request once with the new token. - If the refresh also fails, return the 401 response to the caller.
The frontend also checks token expiry proactively using the
exp claim in the JWT payload (with a 30-second buffer) before making a request, so most refreshes happen silently before a 401 is ever received.Protected endpoints
The following endpoints require a validAuthorization: Bearer <accessToken> header.
| Method | Endpoint | Notes |
|---|---|---|
POST | /api/completions | Submit a challenge completion |
PATCH | /api/completions/:id | Update your own completion |
POST | /api/completions/:id/like | Like a completion |
DELETE | /api/completions/:id/like | Unlike a completion |
GET | /api/users/me | Get your own profile |
PATCH | /api/users/me | Update your profile |
POST | /api/challenges | Create a challenge (admin only) |
POST | /api/flags | Flag a completion |
GET | /api/flags | List all flags (admin only) |
POST | /api/upload | Upload an image |
POST | /api/auth/change-password | Change your password |
Admin-only endpoints additionally require the authenticated user to have
role = "admin". Requests from non-admin users are rejected with HTTP 403.Error responses
| Status | Error | Cause |
|---|---|---|
401 | No token provided | Authorization header is missing or does not start with Bearer |
401 | Invalid or expired token | Token failed Supabase verification |
401 | Authentication failed | Unexpected error during token verification |
403 | Admin access required | Endpoint requires admin role |
Registration flow
New accounts require email verification before the first login.Sign up
POST /api/auth/signup with email, password, and username. A verification code is sent to the provided email.Verify email
POST /api/auth/verify with email and the 6-digit token from the email. On success the response includes accessToken and refreshToken.POST /api/auth/resend with { "email": "..." } to send a new code.
The auth endpoints (
/api/auth/*) are rate-limited to 5 requests per 15 minutes per IP to prevent brute-force attacks.