From fc18665fb78af46dae233d931c365798965b38c0 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sun, 24 Aug 2025 20:12:46 +0300 Subject: [PATCH 1/4] load env from os.env and not directly from .env --- api/routes/auth.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/routes/auth.py b/api/routes/auth.py index 5ada36c3..79ebcdd6 100644 --- a/api/routes/auth.py +++ b/api/routes/auth.py @@ -11,6 +11,7 @@ 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 starlette.config import Config from api.auth.user_management import validate_and_cache_user @@ -280,8 +281,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") From b7840eb0f2534797f169df629e4a45a7b52a0390 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sun, 24 Aug 2025 20:54:20 +0300 Subject: [PATCH 2/4] add tempalte caching --- .gitignore | 3 ++- api/routes/auth.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2a646092..1f416217 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ tests/e2e/screenshots/*.png tmp_* *.d.ts node_modules/ -/app/public/js/* \ No newline at end of file +/app/public/js/* +.jinja_cache/ diff --git a/api/routes/auth.py b/api/routes/auth.py index 79ebcdd6..f7c1d358 100644 --- a/api/routes/auth.py +++ b/api/routes/auth.py @@ -12,6 +12,7 @@ from fastapi.templating import Jinja2Templates from authlib.common.errors import AuthlibBaseError from authlib.integrations.starlette_client import OAuth +from jinja2 import Environment, FileSystemLoader, FileSystemBytecodeCache from starlette.config import Config from api.auth.user_management import validate_and_cache_user @@ -19,7 +20,21 @@ # Router auth_router = APIRouter() TEMPLATES_DIR = str((Path(__file__).resolve().parents[1] / "../app/templates").resolve()) -templates = Jinja2Templates(directory=TEMPLATES_DIR) + +TEMPLATES_CACHE_DIR = "./.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 + ) +) + # ---- Helpers ---- def _get_provider_client(request: Request, provider: str): From df4801ff4e723a9298f40a7415cc454a0d64129e Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sun, 24 Aug 2025 20:59:54 +0300 Subject: [PATCH 3/4] add tempalte caching --- api/routes/auth.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/routes/auth.py b/api/routes/auth.py index f7c1d358..06751f7b 100644 --- a/api/routes/auth.py +++ b/api/routes/auth.py @@ -12,7 +12,7 @@ from fastapi.templating import Jinja2Templates from authlib.common.errors import AuthlibBaseError from authlib.integrations.starlette_client import OAuth -from jinja2 import Environment, FileSystemLoader, FileSystemBytecodeCache +from jinja2 import Environment, FileSystemLoader, FileSystemBytecodeCache, select_autoescape from starlette.config import Config from api.auth.user_management import validate_and_cache_user @@ -31,7 +31,8 @@ directory=TEMPLATES_CACHE_DIR, pattern="%s.cache" ), - auto_reload=True + auto_reload=True, + autoescape=select_autoescape(['html', 'xml', 'j2']) ) ) From 845eb6837946e62db3a0a853d1c6bce42c274bd7 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sun, 24 Aug 2025 21:20:20 +0300 Subject: [PATCH 4/4] change to temp folder --- api/routes/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/routes/auth.py b/api/routes/auth.py index 06751f7b..d8225885 100644 --- a/api/routes/auth.py +++ b/api/routes/auth.py @@ -21,7 +21,7 @@ auth_router = APIRouter() TEMPLATES_DIR = str((Path(__file__).resolve().parents[1] / "../app/templates").resolve()) -TEMPLATES_CACHE_DIR = "./.jinja_cache" +TEMPLATES_CACHE_DIR = "/tmp/jinja_cache" os.makedirs(TEMPLATES_CACHE_DIR, exist_ok=True) # ✅ ensures the folder exists templates = Jinja2Templates(