Spaces:
Running
Running
Update main.py
Browse files
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
|
| 370 |
display_name = data.get('displayName', 'Seeker')
|
| 371 |
|
| 372 |
-
|
| 373 |
-
user_data = {
|
| 374 |
'email': email,
|
| 375 |
'displayName': display_name,
|
| 376 |
-
'credits': 30,
|
| 377 |
'is_admin': False,
|
| 378 |
'createdAt': datetime.utcnow().isoformat()
|
| 379 |
}
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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'])
|