소스 검색

refac: auth endpoint

Timothy Jaeryang Baek 5 달 전
부모
커밋
62e57a4cf5
1개의 변경된 파일22개의 추가작업 그리고 19개의 파일을 삭제
  1. 22 19
      backend/open_webui/routers/auths.py

+ 22 - 19
backend/open_webui/routers/auths.py

@@ -82,27 +82,30 @@ async def get_session_user(
     token = auth_token.credentials
     data = decode_token(token)
 
-    expires_at = data.get("exp")
+    expires_at = None
 
-    if (expires_at is not None) and int(time.time()) > expires_at:
-        raise HTTPException(
-            status_code=status.HTTP_401_UNAUTHORIZED,
-            detail=ERROR_MESSAGES.INVALID_TOKEN,
-        )
+    if data:
+        expires_at = data.get("exp")
 
-    # Set the cookie token
-    response.set_cookie(
-        key="token",
-        value=token,
-        expires=(
-            datetime.datetime.fromtimestamp(expires_at, datetime.timezone.utc)
-            if expires_at
-            else None
-        ),
-        httponly=True,  # Ensures the cookie is not accessible via JavaScript
-        samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
-        secure=WEBUI_AUTH_COOKIE_SECURE,
-    )
+        if (expires_at is not None) and int(time.time()) > expires_at:
+            raise HTTPException(
+                status_code=status.HTTP_401_UNAUTHORIZED,
+                detail=ERROR_MESSAGES.INVALID_TOKEN,
+            )
+
+        # Set the cookie token
+        response.set_cookie(
+            key="token",
+            value=token,
+            expires=(
+                datetime.datetime.fromtimestamp(expires_at, datetime.timezone.utc)
+                if expires_at
+                else None
+            ),
+            httponly=True,  # Ensures the cookie is not accessible via JavaScript
+            samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
+            secure=WEBUI_AUTH_COOKIE_SECURE,
+        )
 
     user_permissions = get_permissions(
         user.id, request.app.state.config.USER_PERMISSIONS