Jack commited on
Commit
4fd350e
·
1 Parent(s): 1543d4d

login fixes

Browse files
Files changed (2) hide show
  1. app/config.py +15 -0
  2. app/main.py +6 -1
app/config.py CHANGED
@@ -9,6 +9,16 @@ BASE_DIR = Path(__file__).resolve().parent.parent
9
  DATA_DIR = BASE_DIR / "data"
10
 
11
 
 
 
 
 
 
 
 
 
 
 
12
  @dataclass(frozen=True)
13
  class Settings:
14
  app_name: str = os.getenv("APP_NAME", "TravelMap")
@@ -17,6 +27,11 @@ class Settings:
17
  f"sqlite:///{(DATA_DIR / 'webarena_airbnb.db').as_posix()}",
18
  )
19
  session_secret: str = os.getenv("SESSION_SECRET", "webarena-airbnb-dev-secret")
 
 
 
 
 
20
  reset_token: str = os.getenv("RESET_TOKEN", "")
21
  host: str = os.getenv("HOST", "0.0.0.0")
22
  port: int = int(os.getenv("PORT", "7860"))
 
9
  DATA_DIR = BASE_DIR / "data"
10
 
11
 
12
+ def _env_bool(name: str, default: bool) -> bool:
13
+ value = os.getenv(name)
14
+ if value is None:
15
+ return default
16
+ return value.strip().lower() in {"1", "true", "yes", "on"}
17
+
18
+
19
+ IS_HUGGINGFACE_SPACE = bool(os.getenv("SPACE_ID") or os.getenv("SPACE_HOST"))
20
+
21
+
22
  @dataclass(frozen=True)
23
  class Settings:
24
  app_name: str = os.getenv("APP_NAME", "TravelMap")
 
27
  f"sqlite:///{(DATA_DIR / 'webarena_airbnb.db').as_posix()}",
28
  )
29
  session_secret: str = os.getenv("SESSION_SECRET", "webarena-airbnb-dev-secret")
30
+ session_same_site: str = os.getenv(
31
+ "SESSION_SAME_SITE",
32
+ "none" if IS_HUGGINGFACE_SPACE else "lax",
33
+ )
34
+ session_https_only: bool = _env_bool("SESSION_HTTPS_ONLY", IS_HUGGINGFACE_SPACE)
35
  reset_token: str = os.getenv("RESET_TOKEN", "")
36
  host: str = os.getenv("HOST", "0.0.0.0")
37
  port: int = int(os.getenv("PORT", "7860"))
app/main.py CHANGED
@@ -35,7 +35,12 @@ app = FastAPI(
35
  title=settings.app_name,
36
  description="A resettable vacation-rental marketplace with booking, messaging, and hosting flows.",
37
  )
38
- app.add_middleware(SessionMiddleware, secret_key=settings.session_secret, same_site="lax")
 
 
 
 
 
39
  app.mount("/static", StaticFiles(directory="app/static"), name="static")
40
  templates = Jinja2Templates(directory="app/templates")
41
 
 
35
  title=settings.app_name,
36
  description="A resettable vacation-rental marketplace with booking, messaging, and hosting flows.",
37
  )
38
+ app.add_middleware(
39
+ SessionMiddleware,
40
+ secret_key=settings.session_secret,
41
+ same_site=settings.session_same_site,
42
+ https_only=settings.session_https_only,
43
+ )
44
  app.mount("/static", StaticFiles(directory="app/static"), name="static")
45
  templates = Jinja2Templates(directory="app/templates")
46