
- Set up FastAPI application with CORS and proper structure - Created User model with SQLAlchemy and SQLite database - Implemented JWT-based authentication with bcrypt password hashing - Added user registration, login, and profile endpoints - Created health check endpoint for monitoring - Set up Alembic for database migrations - Added comprehensive API documentation - Configured proper project structure with separate modules - Updated README with complete setup and usage instructions
User Authentication Service
A FastAPI-based user authentication service with JWT token support.
Features
- User registration and login
- JWT token-based authentication
- Password hashing with bcrypt
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Health check endpoint
- CORS enabled for all origins
- API documentation available at
/docs
and/redoc
Environment Variables
The following environment variables should be set:
SECRET_KEY
: JWT secret key for token signing (defaults to "your-secret-key-change-in-production")
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
API Endpoints
Base
GET /
- Service informationGET /health
- Health check
Authentication
POST /auth/register
- Register a new userPOST /auth/login
- Login userPOST /auth/token
- OAuth2 compatible token endpointGET /auth/me
- Get current user info (requires authentication)POST /auth/logout
- Logout user
Database Structure
The application uses SQLite with the following user table structure:
id
: Primary keyemail
: Unique user emailhashed_password
: Bcrypt hashed passwordis_active
: User status flagcreated_at
: Account creation timestampupdated_at
: Last update timestamp
Development
The project uses Ruff for code formatting and linting.
Description
Languages
Python
95.7%
Mako
4.3%