mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-22 16:36:47 +08:00
Fix tiny issues (#14006)
### What problem does this PR solve? As title ### Type of change - [x] Refactoring <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved authentication error logging to better distinguish between JWT and API token failures. * Enhanced code documentation with clarifying comments for better maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -121,11 +121,12 @@ def _load_user():
|
||||
g.user = user[0]
|
||||
return user[0]
|
||||
except Exception as e_auth:
|
||||
logging.warning(f"load_user got exception {e_auth}")
|
||||
logging.warning(f"load_user from jwt got exception {e_auth}")
|
||||
try:
|
||||
authorization = request.headers.get("Authorization")
|
||||
if len(authorization.split()) == 2:
|
||||
objs = APIToken.query(token=authorization.split()[1])
|
||||
token = authorization.split()[1]
|
||||
objs = APIToken.query(token=token)
|
||||
if objs:
|
||||
user = UserService.query(id=objs[0].tenant_id, status=StatusEnum.VALID.value)
|
||||
if user:
|
||||
@@ -134,8 +135,12 @@ def _load_user():
|
||||
return None
|
||||
g.user = user[0]
|
||||
return user[0]
|
||||
else:
|
||||
logging.warning(f"load_user: No user found for tenant_id={objs[0].tenant_id} from APIToken")
|
||||
else:
|
||||
logging.warning(f"load_user: No APIToken found for token={token[:10]}...")
|
||||
except Exception as e_api_token:
|
||||
logging.warning(f"load_user got exception {e_api_token}")
|
||||
logging.warning(f"load_user from api token got exception {e_api_token}")
|
||||
# Fallback: try raw authorization value as access_token (for login tokens sent without JWT)
|
||||
try:
|
||||
authorization = request.headers.get("Authorization")
|
||||
|
||||
Reference in New Issue
Block a user