Browse Source

Fixed auth check and conftest

JesseFPV 4 months ago
parent
commit
6e5cc55190
2 changed files with 8 additions and 3 deletions
  1. 7 3
      backend/app/core/auth.py
  2. 1 0
      backend/tests/conftest.py

+ 7 - 3
backend/app/core/auth.py

@@ -78,9 +78,13 @@ async def authenticate_user(db: AsyncSession, username: str, password: str) -> U
 
 
 async def is_auth_enabled(db: AsyncSession) -> bool:
 async def is_auth_enabled(db: AsyncSession) -> bool:
     """Check if authentication is enabled."""
     """Check if authentication is enabled."""
-    result = await db.execute(select(Settings).where(Settings.key == "auth_enabled"))
-    setting = result.scalar_one_or_none()
-    return setting and setting.value.lower() == "true"
+    try:
+        result = await db.execute(select(Settings).where(Settings.key == "auth_enabled"))
+        setting = result.scalar_one_or_none()
+        return setting and setting.value.lower() == "true"
+    except Exception:
+        # If settings table doesn't exist or query fails, assume auth is disabled
+        return False
 
 
 
 
 async def get_current_user_optional(
 async def get_current_user_optional(

+ 1 - 0
backend/tests/conftest.py

@@ -59,6 +59,7 @@ async def test_engine():
         project,
         project,
         settings,
         settings,
         smart_plug,
         smart_plug,
+        user,
     )
     )
 
 
     async with engine.begin() as conn:
     async with engine.begin() as conn: