Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ tests/e2e/screenshots/*.png
tmp_*
*.d.ts
node_modules/
/app/public/js/*
/app/public/js/*
.jinja_cache/
23 changes: 20 additions & 3 deletions api/routes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,31 @@
from fastapi.responses import RedirectResponse, HTMLResponse
from fastapi.templating import Jinja2Templates
from authlib.common.errors import AuthlibBaseError
from authlib.integrations.starlette_client import OAuth
from jinja2 import Environment, FileSystemLoader, FileSystemBytecodeCache, select_autoescape
from starlette.config import Config

from api.auth.user_management import validate_and_cache_user

# Router
auth_router = APIRouter()
TEMPLATES_DIR = str((Path(__file__).resolve().parents[1] / "../app/templates").resolve())
templates = Jinja2Templates(directory=TEMPLATES_DIR)

TEMPLATES_CACHE_DIR = "/tmp/jinja_cache"
os.makedirs(TEMPLATES_CACHE_DIR, exist_ok=True) # ✅ ensures the folder exists

templates = Jinja2Templates(
env=Environment(
loader=FileSystemLoader(TEMPLATES_DIR),
bytecode_cache=FileSystemBytecodeCache(
directory=TEMPLATES_CACHE_DIR,
pattern="%s.cache"
),
auto_reload=True,
autoescape=select_autoescape(['html', 'xml', 'j2'])
)
)


# ---- Helpers ----
def _get_provider_client(request: Request, provider: str):
Expand Down Expand Up @@ -280,8 +297,8 @@ async def logout(request: Request) -> RedirectResponse:
# ---- Hook for app factory ----
def init_auth(app):
"""Initialize OAuth and sessions for the app."""
config = Config(".env")
from authlib.integrations.starlette_client import OAuth

config = Config(environ=os.environ)
oauth = OAuth(config)

google_client_id = os.getenv("GOOGLE_CLIENT_ID")
Expand Down
Loading