Markishime commited on
Commit
02bbf6d
·
1 Parent(s): af79a1f

Add URL params fallback for user_id in Firestore save

Browse files

- Check URL params if user_id not found in session state
- Update session state when user_id found in URL params
- Improve logging for debugging user_id issues

Files changed (1) hide show
  1. modules/results.py +19 -1
modules/results.py CHANGED
@@ -947,9 +947,27 @@ def store_analysis_to_firestore(analysis_results, result_id):
947
  user_email = st.session_state.get('user_email', '')
948
  user_name = st.session_state.get('user_name', '')
949
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
950
  # Skip saving to Firestore if user is not authenticated (anonymous users)
951
  if not user_id:
952
- logger.info("Skipping Firestore storage - user ID not found (anonymous user)")
 
 
953
  return False
954
 
955
  # Create the document data structure for Firestore
 
947
  user_email = st.session_state.get('user_email', '')
948
  user_name = st.session_state.get('user_name', '')
949
 
950
+ # If user_id is still empty, try to get from URL params (fallback)
951
+ if not user_id:
952
+ try:
953
+ query_params = st.query_params
954
+ user_id = query_params.get('userId', '')
955
+ if user_id:
956
+ logger.info(f"✅ Retrieved user_id from URL params for Firestore: {user_id}")
957
+ # Also update session state for future use
958
+ st.session_state.user_id = user_id
959
+ if not user_email:
960
+ user_email = query_params.get('userEmail', '')
961
+ if user_email:
962
+ st.session_state.user_email = user_email
963
+ except Exception as e:
964
+ logger.error(f"❌ Failed to get user_id from URL params: {e}")
965
+
966
  # Skip saving to Firestore if user is not authenticated (anonymous users)
967
  if not user_id:
968
+ logger.warning("⚠️ Skipping Firestore storage - user ID not found (anonymous user)")
969
+ logger.warning(f"⚠️ Session state user_id: {st.session_state.get('user_id', 'NOT SET')}")
970
+ logger.warning(f"⚠️ Session state user_config: {st.session_state.get('user_config', {})}")
971
  return False
972
 
973
  # Create the document data structure for Firestore