
- Set up FastAPI project structure with main.py and requirements.txt - Create User model with SQLAlchemy and SQLite database - Implement JWT token-based authentication system - Add password hashing with bcrypt - Create auth endpoints: register, login, and protected /me route - Set up Alembic for database migrations - Add health check endpoint with database status - Configure CORS to allow all origins - Update README with setup instructions and environment variables
User Authentication Service
A FastAPI-based user authentication service with JWT token support and SQLite database.
Features
- User registration and login
- JWT token-based authentication
- Password hashing with bcrypt
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- CORS enabled for all origins
- Health check endpoint
- API documentation at
/docs
and/redoc
Installation
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables (optional):
export SECRET_KEY="your-secret-key-here"
export ACCESS_TOKEN_EXPIRE_MINUTES="30"
Running the Application
Start the development server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Endpoints
GET /
- Service informationPOST /auth/register
- Register a new userPOST /auth/login
- Login and get access tokenGET /auth/me
- Get current user info (requires authentication)GET /health
- Health check endpointGET /docs
- Interactive API documentationGET /redoc
- Alternative API documentation
Environment Variables
SECRET_KEY
- Secret key for JWT token signing (default: "your-secret-key-change-this-in-production")ACCESS_TOKEN_EXPIRE_MINUTES
- Token expiration time in minutes (default: 30)
Database
The application uses SQLite database stored at /app/storage/db/db.sqlite
. Database migrations are managed with Alembic.
Description
Languages
Python
95.2%
Mako
4.8%