webcodelab commited on
Commit
acd870f
·
verified ·
1 Parent(s): fd3456c

Update app/routes.py

Browse files
Files changed (1) hide show
  1. app/routes.py +9 -10
app/routes.py CHANGED
@@ -310,22 +310,21 @@ def regenerate_api_key():
310
  flash('Please log in.')
311
  return redirect(url_for('auth.login'))
312
 
313
- new_api_key = generate_api_key()
314
  user_id = session['user_id']
 
315
 
316
- patch = requests.patch(
317
  f"{SUPABASE_URL}/rest/v1/users?id=eq.{user_id}",
318
- headers=HEADERS,
319
- json={"api_key": new_api_key}
320
  )
321
 
322
- if patch.status_code == 204:
323
- flash('✅ New API key generated.')
324
- else:
325
- print("❌ Failed to update API key:", patch.text)
326
- flash('Failed to regenerate API key.')
327
 
328
- return redirect(url_for('auth.dashboard'))
 
329
 
330
 
331
  @auth.route('/logout')
 
310
  flash('Please log in.')
311
  return redirect(url_for('auth.login'))
312
 
 
313
  user_id = session['user_id']
314
+ new_key = generate_api_key()
315
 
316
+ res = requests.patch(
317
  f"{SUPABASE_URL}/rest/v1/users?id=eq.{user_id}",
318
+ headers={**HEADERS, "Content-Type": "application/json"},
319
+ json={"api_key": new_key}
320
  )
321
 
322
+ if res.status_code != 200:
323
+ flash("Failed to regenerate API key.")
324
+ return redirect(url_for('auth.api_keys'))
 
 
325
 
326
+ flash("API key regenerated successfully.")
327
+ return redirect(url_for('auth.api_keys'))
328
 
329
 
330
  @auth.route('/logout')