Skip to content

Commit ec27347

Browse files
committed
Fix: decode before creating in db
1 parent f3ca1fb commit ec27347

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

  • src/discord-cluster-manager/api

src/discord-cluster-manager/api/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,20 @@ async def cli_auth(code: str, state: str = None):
117117
user_id = user_json.get("id")
118118
user_name = user_json.get("username")
119119

120+
if not state:
121+
raise HTTPException(status_code=400, detail="State parameter with CLI ID is required")
122+
123+
try:
124+
cli_id = base64.b64decode(state).decode("utf-8")
125+
except Exception as e:
126+
raise HTTPException(status_code=400, detail=f"Invalid state parameter: {str(e)}") from e
127+
120128
with bot_instance.leaderboard_db as db:
121129
try:
122-
db.create_user_from_cli(user_id, user_name, state)
130+
db.create_user_from_cli(user_id, user_name, cli_id)
123131
except Exception as e:
124132
raise HTTPException(status_code=400, detail="Failed to create user") from e
125133

126-
cli_id = ""
127-
if state:
128-
try:
129-
cli_id = base64.b64decode(state).decode("utf-8")
130-
except Exception as e:
131-
raise HTTPException(status_code=400, detail=f"Invalid state parameter: {str(e)}") from e
132-
133134
return {"status": "success", "user_id": user_id, "cli_id": cli_id, "user_name": user_name}
134135

135136

0 commit comments

Comments
 (0)