Automated Action b7392c9694 Add user authentication flow with FastAPI
- 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
2025-06-20 10:53:35 +00:00

1.4 KiB

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

  1. Install dependencies:
pip install -r requirements.txt
  1. 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 information
  • POST /auth/register - Register a new user
  • POST /auth/login - Login and get access token
  • GET /auth/me - Get current user info (requires authentication)
  • GET /health - Health check endpoint
  • GET /docs - Interactive API documentation
  • GET /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.