Overview
The André Ruperto Portfolio API uses JWT (JSON Web Tokens) for authentication. Protected endpoints require a valid JWT token in theAuthorization header.
Login Endpoint
This endpoint is rate limited to 5 requests per 15 minutes to prevent brute force attacks.
POST /api/auth/login
Authenticate with admin password to receive a JWT token.
Request Body
Admin password for authentication
Response
Indicates successful authentication
JWT token valid for 24 hours
Example Request
cURL
JavaScript
Example Response
Success (200)
Error - Invalid Password (401)
Error - Rate Limited (429)
Using the Token
Once you have a JWT token, include it in theAuthorization header for protected endpoints:
Authorization Header
Alternative: Query Parameter
You can also pass the token as a query parameter (useful for browser previews):Protected Endpoints
The following endpoints require authentication:POST /api/projects- Create a new projectPUT /api/projects/:id- Update a projectDELETE /api/projects/:id- Delete a projectGET /api/admin/email-preview/notification- Preview notification emailGET /api/admin/email-preview/confirmation- Preview confirmation email
Token Expiration
JWT tokens are valid for 24 hours from the time of issuance. After expiration, you must authenticate again to receive a new token.Error Handling
Security Best Practices
Store Securely
Never store JWT tokens in local storage. Use secure, httpOnly cookies when possible.
HTTPS Only
Always use HTTPS in production to prevent token interception.
Refresh Tokens
Re-authenticate before the 24-hour expiration to maintain access.
Environment Variables
Store admin password and JWT secret in environment variables, never in code.
Implementation Details
The authentication system (backend/src/server.js:58-76):- Uses
jsonwebtokenlibrary for JWT creation and verification - Signs tokens with
JWT_SECRETfrom environment variables - Validates tokens via middleware before accessing protected routes
- Supports both header and query parameter authentication
