Skip to content

Commit 53c696a

Browse files
committed
Add logging to see why sometimes API keys are rejected
1 parent c9c05d0 commit 53c696a

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

app/core/security.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ async def verify_token(request: Request, credentials: Optional[HTTPAuthorization
166166
}
167167
key_id = decoded["key_id"]
168168
# Verify key hasn't been removed
169+
print("Got key_id: ", key_id)
169170
results = db.table("api_keys").select('*').eq('key_id', key_id).execute()
171+
print("Results: " + str(results))
170172
if not results.data or not results.data[0]:
171173
raise HTTPException(status_code=401, detail="API key not found (it may have been removed)")
172174
else:
@@ -197,7 +199,8 @@ async def verify_token(request: Request, credentials: Optional[HTTPAuthorization
197199
}).execute()
198200

199201
from app.services.credits import CreditService
200-
balance = await CreditService.refresh_user_credits(user_id, is_guest, credits)
202+
balance = await CreditService.refresh_user_credits(user_id, is_guest, credits)
203+
print("Updated user balance: ", balance)
201204
return {
202205
"user_id": user_id,
203206
"is_guest": is_guest,

app/services/credits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def get_credits(user_id: str) -> int:
3333
async def deduct_credits(user_id: str, operation: str, data_size: int, bytes: int) -> bool:
3434
"""Deduct credits after successful operation"""
3535
cost = await CreditService.get_operation_cost(operation, data_size, bytes)
36-
print(f"Deducting {cost} credits for {operation} with {data_size} statements and a total of {bytes} bytes")
36+
print(f"Deducting {cost} credits from {user_id} for {operation} with {data_size} statements and a total of {bytes} bytes")
3737
result = db.rpc(
3838
'deduct_credits',
3939
{

0 commit comments

Comments
 (0)