
- Removed unused imports in deps.py, routes/auth.py, and models/user.py - Code is now lint-free and follows best practices - Complete FastAPI user authentication service with JWT token support generated with BackendIM... (backend.im)
87 lines
2.0 KiB
Markdown
87 lines
2.0 KiB
Markdown
# User Authentication Service
|
|
|
|
A FastAPI-based user authentication service with JWT authentication.
|
|
|
|
## Features
|
|
|
|
- User registration and login
|
|
- JWT authentication
|
|
- User profile management
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic migrations
|
|
- Health check endpoint
|
|
|
|
## Requirements
|
|
|
|
- Python 3.8+
|
|
- FastAPI
|
|
- SQLAlchemy
|
|
- Alembic
|
|
- Pydantic
|
|
- Python-jose (JWT)
|
|
- Passlib (Password hashing)
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── alembic/ # Database migrations
|
|
├── app/ # Application code
|
|
│ ├── api/ # API endpoints
|
|
│ │ ├── deps.py # Dependencies
|
|
│ │ └── routes/ # API route handlers
|
|
│ ├── core/ # Core functionality
|
|
│ │ ├── config.py # Configuration settings
|
|
│ │ └── security.py # Security utilities
|
|
│ ├── db/ # Database
|
|
│ │ ├── crud.py # CRUD operations
|
|
│ │ └── session.py # DB session
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ └── schemas/ # Pydantic schemas
|
|
├── alembic.ini # Alembic configuration
|
|
├── main.py # FastAPI application
|
|
└── requirements.txt # Dependencies
|
|
```
|
|
|
|
## Setup
|
|
|
|
1. Clone the repository
|
|
2. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
3. Run the migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
4. Start the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### Authentication
|
|
|
|
- `POST /api/v1/auth/register` - Register a new user
|
|
- `POST /api/v1/auth/login` - Login and get JWT token
|
|
- `GET /api/v1/auth/me` - Get current user info (requires authentication)
|
|
|
|
### Health Check
|
|
|
|
- `GET /health` - Check service health
|
|
|
|
## API Documentation
|
|
|
|
- Swagger UI: `/docs`
|
|
- ReDoc: `/redoc`
|
|
|
|
## Development
|
|
|
|
To run the application in development mode:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
This application was bootstrapped by BackendIM, the AI-powered backend generation platform. |