Overview
Better Uptime uses JWT (JSON Web Tokens) for API authentication. The API supports both traditional email/password authentication and GitHub OAuth.Authentication Flow
The API provides two types of procedures:- Public Procedures: Available to all users without authentication
- Protected Procedures: Require a valid JWT token in the Authorization header
Context Creation
Every API request creates a context that includes the authenticated user (if any):Public Procedures
Public procedures are accessible without authentication:Protected Procedures
Protected procedures require authentication and throw anUNAUTHORIZED error if no valid token is provided:
Login Flow
Email/Password Authentication
Users can log in with email and password:GitHub OAuth Flow
Better Uptime supports GitHub OAuth for seamless authentication:Making Authenticated Requests
From the Client
Include the JWT token in the Authorization header:Token Storage
Store the JWT token securely:- Web: Use httpOnly cookies or secure localStorage
- Mobile: Use secure storage (Keychain/Keystore)
- Server: Store in environment variables
Email Verification
New users must verify their email before logging in:Token Expiration
JWT tokens expire after 1 hour. Clients should:- Handle
UNAUTHORIZEDerrors - Prompt user to log in again
- Implement token refresh (if needed)
Security Best Practices
Store JWT_SECRET securely
Store JWT_SECRET securely
Never commit your
JWT_SECRET to version control. Use environment variables:Use HTTPS in production
Use HTTPS in production
Always use HTTPS to prevent token interception:
Validate token expiration
Validate token expiration
Set appropriate token expiration times and implement refresh logic:
Sanitize user input
Sanitize user input
Always validate and sanitize user input using Zod schemas:
Next Steps
User Router
Explore authentication endpoints in detail
Protected Routes
Learn about protected website monitoring endpoints