Automated Action aae9527254 Set up user authentication flow with FastAPI and SQLite
- Created user model with SQLAlchemy ORM
- Implemented authentication with JWT tokens (access and refresh tokens)
- Added password hashing with bcrypt
- Created API endpoints for registration, login, and user management
- Set up Alembic for database migrations
- Added health check endpoint
- Created role-based access control (standard users and superusers)
- Added comprehensive documentation
2025-06-10 15:58:57 +00:00

67 lines
1.6 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from app.api.v1.api import api_router
from app.core.config import settings
app = FastAPI(
title=settings.PROJECT_NAME,
description=settings.PROJECT_DESCRIPTION,
version=settings.PROJECT_VERSION,
)
# Set up CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API router
app.include_router(api_router, prefix=settings.API_V1_STR)
# Define custom OpenAPI schema
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title=settings.PROJECT_NAME,
version=settings.PROJECT_VERSION,
description=settings.PROJECT_DESCRIPTION,
routes=app.routes,
)
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
@app.get("/", tags=["Root"])
async def root():
"""
Root endpoint providing basic service information.
"""
return {
"title": settings.PROJECT_NAME,
"documentation": "/docs",
"health_check": "/health"
}
@app.get("/health", tags=["Health"])
async def health():
"""
Health check endpoint to verify service status.
"""
return {
"status": "healthy",
"version": settings.PROJECT_VERSION
}
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)