fix(auth): Update API response parsing to handle nested structure
- Fix 'id_user' key not found error by navigating the correct nested path - Extract id_user from data.user.applications[0].users[0].id_user - Add fallback to old structure for backward compatibility - Prevents authentication failures due to API response format changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,13 @@ class AuthHandler:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
login_data: Dict[str, Any] = response.json()
|
login_data: Dict[str, Any] = response.json()
|
||||||
self.user_id = str(login_data["data"]["user"]["id_user"])
|
# Try to find id_user in the nested structure
|
||||||
|
try:
|
||||||
|
# First try the new structure: data.user.applications[0].users[0].id_user
|
||||||
|
self.user_id = str(login_data["data"]["user"]["applications"][0]["users"][0]["id_user"])
|
||||||
|
except (KeyError, IndexError, TypeError):
|
||||||
|
# Fallback to old structure if it exists
|
||||||
|
self.user_id = str(login_data["data"]["user"]["id_user"])
|
||||||
except (KeyError, ValueError) as e:
|
except (KeyError, ValueError) as e:
|
||||||
logging.error(f"Error during login: {str(e)} - Response: {response.text}")
|
logging.error(f"Error during login: {str(e)} - Response: {response.text}")
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user