This is the API server for the 0to100 application.
This project is being migrated from MongoDB to Supabase for database, authentication, and storage. Below are the steps for migration:
- Create a Supabase project at https://supabase.com
- Get your Supabase URL and anon key from the project settings
- Add these values to your environment variables
Add the following variables to your .env file:
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
-
Set up the database schema:
- Run the SQL in
migrations/supabase-schema.sqlin the Supabase SQL editor - This creates all necessary tables with proper relationships and security policies
- Run the SQL in
-
Migrate your data:
npm run migrate:data
-
Migrate your files:
npm run migrate:files:avatars npm run migrate:files:programs
You can test your Supabase connection with:
npm run test:supabaseDuring the migration phase, the API supports both MongoDB and Supabase.
- MongoDB auth routes:
/auth/* - Supabase auth routes:
/auth/supabase/* - MongoDB tasks API:
/tasks/* - Supabase tasks API:
/tasks/supabase/*
To fully switch to Supabase, update the API routes in your client application to use the Supabase endpoints.
The following endpoints are available for the Supabase tasks API:
GET /tasks/supabase- Get tasks for a specific dayGET /tasks/supabase/:userId/:day- Get tasks for a specific user and dayPOST /tasks/supabase/populate- Populate tasks for a day based on user's program subscriptionsPATCH /tasks/supabase/:id/complete- Toggle completion status of a taskDELETE /tasks/supabase/:id/delete- Delete a task (or mark as deleted for program-related tasks)POST /tasks/supabase/new- Create a new task
When deploying to production:
- Ensure all environment variables are properly set
- Run the migration scripts on your production server
- Update client-side code to use the new API endpoints
npm run dev # Development mode
npm run test # Test mode
npm run prod # Production modePOST /auth/register- Register a new userPOST /auth/login- Login a userPOST /auth/request-reset- Request password resetPOST /auth/reset-password- Reset password
For detailed API documentation, refer to the API specification document.
The 0to100 API implements the following security measures:
-
Password Security:
- Passwords are never stored in plain text
- All passwords are hashed using bcrypt with unique salts
- Password hashing is performed server-side
-
Transport Security:
- Development: HTTP for easier local development
- Production: HTTPS with proper certificates
- All production traffic is encrypted
-
Authentication:
- JWT tokens with 12-hour expiration
- Secure cookies in production environments
- Rate limiting on authentication endpoints
-
API Security:
- CORS protection with allowlist of domains
- Helmet.js for HTTP security headers
- Rate limiting to prevent abuse
To run the API in development mode:
npm run dev
For production, you'll need to:
- Generate proper SSL certificates
- Add them to the
certsdirectory asserver.certandserver.key - Set environment to production:
NODE_ENV=production - Run with:
npm run prod