Overview
The login endpoint authenticates users using Supabase Auth. JCV Fitness supports two authentication methods:- Password Authentication - Traditional email and password login
- Magic Link - Passwordless authentication via email link
Endpoint
Authentication
This endpoint does not require authentication.Password Login
Request Body
User’s registered email address.
User’s password.
Authentication method. Use
"password" for this flow.Response
The authenticated session object.
The authenticated user object.
Request Example
cURL
JavaScript
Response Example
Magic Link Login
Request Body
User’s registered email address.
Authentication method. Use
"magic_link" for this flow.Response
Always
true when magic link is sent successfully.Confirmation message indicating that the magic link was sent.
Request Example
cURL
JavaScript
Response Example
Error Codes
| Code | Description |
|---|---|
INVALID_CREDENTIALS | Email or password is incorrect |
EMAIL_NOT_CONFIRMED | User has not confirmed their email address |
USER_NOT_FOUND | No account exists with this email |
RATE_LIMIT_EXCEEDED | Too many login attempts or magic link requests |
SUPABASE_ERROR | Internal error from Supabase Auth service |
Implementation Details
Password Authentication Flow
- Client submits email and password
- Supabase Auth verifies credentials against
auth.userstable - If valid, returns JWT access token and refresh token
- Client stores tokens (typically in httpOnly cookies or secure storage)
- Client includes access token in Authorization header for protected API requests
- When access token expires, client uses refresh token to get a new one
Magic Link Flow
- Client submits email address
- Supabase generates one-time use token
- Supabase sends email with magic link containing token
- User clicks link in email
- Link redirects to callback URL:
https://jcv24fitness.com/auth/callback?token=...&type=magiclink - Callback page exchanges token for session
- User is authenticated and redirected to dashboard
Session Management
Supabase automatically manages session state:- Access tokens expire after 1 hour (3600 seconds)
- Refresh tokens are valid for 30 days
- Sessions are automatically refreshed when accessing protected routes
- Session state is synchronized across browser tabs
Frontend Integration
Password Login
Magic Link Login
Protected Routes
Use theProtectedRoute component to guard routes that require authentication:
The
useAuth hook provides isAuthenticated and isLoading states to conditionally render UI based on auth status.Security Considerations
- Passwords are hashed using bcrypt before storage (handled by Supabase)
- Access tokens are short-lived (1 hour) to minimize risk if compromised
- Rate limiting prevents brute force attacks
- Magic links are single-use and expire after 1 hour
- Row Level Security (RLS) ensures users can only access their own data