Built with FastAPI and SQLAlchemy, this service provides essential user management functionality out of the box and is ready to deploy. Designed for rapid development and easy extension, it helps technical founders go from idea to launch with minimal backend overhead.
Lean enough for your MVP. Strong enough to scale with you.
- 🔐 Secure user registration, login, and token-based authentication
- 📨 Built-in email verification and password reset flows
- ⚡ Asynchronous background tasks for fast user experiences
- 🛡️ Protected route examples
- 📊 Event tracking for analytics and user behavior insights
- 🛠️ Easily extendable (Third-party OAuth authentication, roles, etc.)
- FastAPI — lightning-fast Python web framework
- SQLAlchemy — ORM for database interactions
- SQLite — Local development database
- PostgreSQL — Production database
- SendGrid — Email platform
- Railway — Deployment platform
git clone https://github.com/bb220/auth-api.git
cd auth-apipython -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activatepip install -r requirements-dev.txt# Secret Key for JWT signing
SECRET_KEY=your_super_secret_key_here
# Access Token Expiry Time (minutes)
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Refresh Token Expiry Time (minutes)
REFRESH_TOKEN_EXPIRE_MINUTES=10080 # 7 days
# Database URL (SQLite local example)
DATABASE_URL=sqlite:///./auth_api.db
# SendGrid API Key for sending emails
SENDGRID_API_KEY=your_sendgrid_api_key_here
# Verified sender email (must match your SendGrid authenticated domain)
FROM_EMAIL_ADDRESS=your_verified_sender@example.com
# Frontend domain used for links in the emails
FRONTEND_DOMAIN=https://yourfrontend.com✅ In deployed environments, all env variables are managed securely with Railway.
uvicorn app.main:app --reload- API documentation: http://127.0.0.1:8000/docs
- OpenAPI schema: http://127.0.0.1:8000/openapi.json
🚀 Deploy with Railway
Launch hosted environments in minutes through Railway's console.
- Create a project with the GitHub integration.
- Set the app's
Custom Start Command
uvicorn app.main:app --host 0.0.0.0 --port $PORT- Create a Postgres DB
- Set the app's environment variables
- Create a SendGrid account (free tier works)
- Verify your sender email address or domain
- Create an API Key and include in your environment variables
| Method | Route | Purpose |
|---|---|---|
| POST | /register |
Register a new user |
| GET | /verify-email |
Verify email using a token |
| POST | /login |
Login and get access + refresh tokens |
| POST | /refresh |
Refresh access token |
| POST | /resend-verification-email |
Request resend of verification email |
| GET | /protected |
Example secured endpoint |
| Method | Endpoint | Description |
|---|---|---|
POST |
/request-password-reset |
Request password reset email |
POST |
/reset-password |
Reset password using token from email |
This API includes built-in event tracking for critical user actions.
Events are recorded into the events database table for monitoring, reporting, and analysis.
| Event Name | Trigger |
|---|---|
user_registered |
After successful user registration |
user_login_success |
After successful user login |
user_login_failure |
After failed user login attempt |
password_reset_requested |
When a password reset is requested |
password_reset_completed |
After a successful password reset |
email_verified |
After user successfully verifies their email |
protected_route_accessed |
When an authenticated user accesses a protected route |
When adding new routes or features, developers should:
- Identify key success and/or failure points.
- Use the record_event utility to capture meaningful events.
- Include useful metadata where relevant.
- Passwords securely hashed
- Access and Refresh tokens expire upon password changes
- CORS only allows trusted frontend origins
- Cooldown/rate limit to protect sensitive email actions
- HttpOnly cookies for refresh token
- OAuth integrations
This project is licensed under the MIT License.
Built by bb220 Open to feedback and collaboration!
