added logging to troubleshoot refresh token issue
This commit is contained in:
parent
67ceca2777
commit
6031f9893d
2 changed files with 14 additions and 2 deletions
Binary file not shown.
|
|
@ -87,21 +87,29 @@ async def refresh_token(
|
|||
db: AsyncIOMotorDatabase = Depends(get_database),
|
||||
):
|
||||
refresh_token = request.cookies.get("refresh_token")
|
||||
print(f"🔍 REFRESH DEBUG: Cookie exists: {bool(refresh_token)}")
|
||||
|
||||
if not refresh_token:
|
||||
print("🚨 REFRESH ERROR: No refresh token in cookies")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Refresh token not found",
|
||||
)
|
||||
|
||||
try:
|
||||
print(f"🔍 REFRESH DEBUG: Attempting to decode token...")
|
||||
payload = decode_token(refresh_token)
|
||||
print(f"🔍 REFRESH DEBUG: Token decoded successfully, type={payload.get('type')}")
|
||||
|
||||
if payload.get("type") != "refresh":
|
||||
print(f"🚨 REFRESH ERROR: Wrong token type: {payload.get('type')}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid token type",
|
||||
)
|
||||
|
||||
user_id = payload.get("sub")
|
||||
print(f"🔍 REFRESH DEBUG: User ID from token: {user_id}")
|
||||
if not user_id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
|
|
@ -138,16 +146,20 @@ async def refresh_token(
|
|||
max_age=settings.jwt_refresh_ttl_days * 24 * 60 * 60,
|
||||
)
|
||||
|
||||
print(f"🔍 REFRESH DEBUG: Refresh successful for user {user_id}")
|
||||
return RefreshResponse(
|
||||
access_token=new_access_token,
|
||||
user_id=user_id,
|
||||
role=user.role.value
|
||||
)
|
||||
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
print(f"🚨 REFRESH ERROR: Exception during refresh: {type(e).__name__}: {e}")
|
||||
import traceback
|
||||
print(f"Traceback:\n{traceback.format_exc()}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid refresh token",
|
||||
detail=f"Invalid refresh token: {str(e)}",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue