from fastapi import Depends, FastAPI from fastapi.middleware.cors import CORSMiddleware from app.models.user import User from app.schemas.user import UserCreate, UserRead, UserUpdate from app.services.user_service import auth_backend, current_active_verified_user, fastapi_users app = FastAPI() # CORS for frontend dev server app.add_middleware( CORSMiddleware, allow_origins=[ "http://localhost:5173", "http://127.0.0.1:5173", ], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router( fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"] ) app.include_router( fastapi_users.get_register_router(UserRead, UserCreate), prefix="/auth", tags=["auth"], ) app.include_router( fastapi_users.get_reset_password_router(), prefix="/auth", tags=["auth"], ) app.include_router( fastapi_users.get_verify_router(UserRead), prefix="/auth", tags=["auth"], ) app.include_router( fastapi_users.get_users_router(UserRead, UserUpdate), prefix="/users", tags=["users"], ) # Liveness/root endpoint @app.get("/", include_in_schema=False) async def root(): return {"status": "ok", "message": "Welcome to the FastAPI application!"} @app.get("/authenticated-route") async def authenticated_route(user: User = Depends(current_active_verified_user)): return {"message": f"Hello {user.email}!"}