mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
from fastapi import Depends, FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.models.user import User
|
|
|
|
from app.services.user_service import current_active_verified_user
|
|
from app.api.auth import router as auth_router
|
|
from app.api.categories import router as categories_router
|
|
from app.api.transactions import router as transactions_router
|
|
from app.services.user_service import auth_backend, current_active_verified_user, fastapi_users, get_oauth_provider
|
|
|
|
fastApi = FastAPI()
|
|
|
|
# CORS for frontend dev server
|
|
fastApi.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
"http://localhost:5173",
|
|
"http://127.0.0.1:5173",
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
fastApi.include_router(auth_router)
|
|
fastApi.include_router(categories_router)
|
|
fastApi.include_router(transactions_router)
|
|
|
|
fastApi.include_router(
|
|
fastapi_users.get_oauth_router(
|
|
get_oauth_provider("MojeID"),
|
|
auth_backend,
|
|
"SECRET",
|
|
associate_by_email=True,
|
|
),
|
|
prefix="/auth/mojeid",
|
|
tags=["auth"],
|
|
)
|
|
|
|
fastApi.include_router(
|
|
fastapi_users.get_oauth_router(
|
|
get_oauth_provider("BankID"),
|
|
auth_backend,
|
|
"SECRET",
|
|
associate_by_email=True,
|
|
),
|
|
prefix="/auth/bankid",
|
|
tags=["auth"],
|
|
)
|
|
|
|
|
|
# Liveness/root endpoint
|
|
@fastApi.get("/", include_in_schema=False)
|
|
async def root():
|
|
return {"status": "ok"}
|
|
|
|
|
|
@fastApi.get("/authenticated-route")
|
|
async def authenticated_route(user: User = Depends(current_active_verified_user)):
|
|
return {"message": f"Hello {user.email}!"}
|