rairo commited on
Commit
c109445
·
verified ·
1 Parent(s): 017440b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -6
main.py CHANGED
@@ -364,22 +364,43 @@ def admin_dashboard():
364
 
365
  @app.route('/api/auth/signup', methods=['POST'])
366
  def signup():
 
 
 
 
 
 
 
 
 
367
  try:
 
 
 
 
 
 
 
 
368
  data = request.get_json()
369
- email, password = data.get('email'), data.get('password')
370
  display_name = data.get('displayName', 'Seeker')
371
 
372
- user = auth.create_user(email=email, password=password, display_name=display_name)
373
- user_data = {
374
  'email': email,
375
  'displayName': display_name,
376
- 'credits': 30, # Bumped to 30 for Athena Seeker
377
  'is_admin': False,
378
  'createdAt': datetime.utcnow().isoformat()
379
  }
380
- db_ref.child(f'users/{user.uid}').set(user_data)
381
- return jsonify({'uid': user.uid, **user_data}), 201
 
 
 
 
382
  except Exception as e:
 
383
  return jsonify({'error': str(e)}), 400
384
 
385
  @app.route('/api/auth/social-signin', methods=['POST'])
 
364
 
365
  @app.route('/api/auth/signup', methods=['POST'])
366
  def signup():
367
+ """
368
+ Refined Signup: Handles syncing after the Frontend creates the user.
369
+ Does not try to re-create the user in Firebase Auth.
370
+ """
371
+ # 1. Verify the token sent by the frontend
372
+ uid = verify_token(request.headers.get('Authorization'))
373
+ if not uid:
374
+ return jsonify({'error': 'Invalid or expired token'}), 401
375
+
376
  try:
377
+ user_ref = db_ref.child(f'users/{uid}')
378
+ user_data = user_ref.get()
379
+
380
+ # 2. If user already exists in DB, just return it (avoid error)
381
+ if user_data:
382
+ return jsonify({'uid': uid, **user_data}), 200
383
+
384
+ # 3. User is new to the DB, initialize their profile
385
  data = request.get_json()
386
+ email = data.get('email')
387
  display_name = data.get('displayName', 'Seeker')
388
 
389
+ new_user_record = {
 
390
  'email': email,
391
  'displayName': display_name,
392
+ 'credits': 30, # Ensure they get their starting Sparks
393
  'is_admin': False,
394
  'createdAt': datetime.utcnow().isoformat()
395
  }
396
+
397
+ user_ref.set(new_user_record)
398
+ print(f"Successfully initialized Seeker profile for UID: {uid}")
399
+
400
+ return jsonify({'success': True, 'uid': uid, **new_user_record}), 201
401
+
402
  except Exception as e:
403
+ print(f"Signup Sync Error: {e}")
404
  return jsonify({'error': str(e)}), 400
405
 
406
  @app.route('/api/auth/social-signin', methods=['POST'])