
- Set up FastAPI application with SQLite database - Create User model with email and password fields - Implement JWT token-based authentication - Add user registration and login endpoints - Create protected user profile endpoints - Configure Alembic for database migrations - Add password hashing with bcrypt - Include CORS middleware and health endpoint - Update README with setup and usage instructions Environment variables required: - SECRET_KEY: JWT secret key for token signing
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.api.routes import auth, users
|
|
from app.db.session import engine
|
|
from app.db.base import Base
|
|
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="User Authentication Service",
|
|
description="A FastAPI service for user authentication",
|
|
version="1.0.0",
|
|
openapi_url="/openapi.json"
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router, prefix="/api/v1/auth", tags=["authentication"])
|
|
app.include_router(users.router, prefix="/api/v1/users", tags=["users"])
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"title": "User Authentication Service",
|
|
"documentation": "/docs",
|
|
"health": "/health"
|
|
}
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {
|
|
"status": "healthy",
|
|
"service": "User Authentication Service",
|
|
"version": "1.0.0"
|
|
} |