Automated Action 8575427c43 Implement user authentication flow
- Setup project structure with FastAPI
- Create user models with SQLAlchemy
- Implement JWT authentication
- Create auth endpoints (register, login, me)
- Add health endpoint
- Generate Alembic migrations
- Update documentation

Generated with BackendIM... (backend.im)
2025-05-12 17:00:50 +00:00

2.6 KiB

User Authentication Flow Service

A FastAPI service that provides a complete user authentication flow with JWT tokens.

Features

  • User registration with email and username
  • User login with JWT token generation
  • Password hashing with bcrypt
  • Authentication middleware and dependencies
  • User data retrieval
  • Health check endpoint
  • SQLite database with SQLAlchemy ORM

Project Structure

.
├── app/
│   ├── api/
│   │   ├── deps.py         # Dependency injection
│   │   ├── endpoints/      # API endpoints
│   │   └── api.py          # API router
│   ├── core/
│   │   ├── config.py       # Application configuration
│   │   └── security.py     # Security utilities
│   ├── db/
│   │   └── session.py      # Database session
│   ├── models/
│   │   └── user.py         # SQLAlchemy models
│   ├── schemas/
│   │   ├── auth.py         # Auth-related schemas
│   │   ├── token.py        # Token schemas
│   │   └── user.py         # User schemas
│   └── services/
│       └── user.py         # User service
├── migrations/             # Alembic migrations
├── storage/
│   └── db/                 # SQLite database
├── alembic.ini             # Alembic configuration
├── main.py                 # Application entry point
└── requirements.txt        # Python dependencies

Getting Started

Prerequisites

  • Python 3.8 or higher

Installation

  1. Clone the repository:
git clone <repository-url>
cd userauthenticationflowservice
  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head
  1. Start the server:
uvicorn main:app --reload

The API will be available at http://localhost:8000.

API documentation is available at:

API Endpoints

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login and get access token
  • GET /api/v1/auth/me - Get current user information (requires authentication)

Health Check

  • GET /health - Check application health status

Environment Variables

The application uses environment variables for configuration. These can be set in a .env file:

  • SECRET_KEY - Secret key for JWT token generation
  • ACCESS_TOKEN_EXPIRE_MINUTES - Token expiration time in minutes
  • DEBUG - Debug mode (true/false)

License

This project is licensed under the MIT License.