FauziIsyrinApridal commited on
Commit
5b8619b
·
1 Parent(s): b17b0dd
Files changed (1) hide show
  1. app/auth.py +23 -10
app/auth.py CHANGED
@@ -29,14 +29,18 @@ def auth_view():
29
  unsafe_allow_html=True
30
  )
31
 
32
- # --- FIX: Auto convert hash (#) to query (?) using streamlit-url-fragment ---
 
 
33
  try:
34
  from streamlit_url_fragment import get_fragment
35
  fragment = get_fragment()
 
36
 
37
  if fragment and not st.session_state.get("hash_migrated"):
38
  # Parse fragment parameters
39
  params = dict(parse_qsl(fragment))
 
40
 
41
  if params.get("type") == "recovery" and params.get("access_token"):
42
  # Set query params so existing recovery flow works
@@ -47,20 +51,29 @@ def auth_view():
47
  st.experimental_set_query_params(**params)
48
 
49
  st.session_state["hash_migrated"] = True
 
50
  st.rerun()
51
- except ImportError:
52
- # Fallback to JS if library not available
 
 
 
53
  st.markdown(
54
  """
55
  <script>
56
  (function() {
57
- const hash = window.location.hash;
58
- if (hash && hash.length > 1 && !sessionStorage.getItem("hash_migrated")) {
59
- const query = hash.substring(1);
60
- const newUrl = window.location.pathname + "?" + query;
61
- sessionStorage.setItem("hash_migrated", "true");
62
- window.history.replaceState(null, "", newUrl);
63
- window.location.reload();
 
 
 
 
 
64
  }
65
  })();
66
  </script>
 
29
  unsafe_allow_html=True
30
  )
31
 
32
+ # --- DEBUG & FIX: Auto convert hash (#) to query (?) ---
33
+ # Try streamlit-url-fragment first
34
+ fragment_detected = False
35
  try:
36
  from streamlit_url_fragment import get_fragment
37
  fragment = get_fragment()
38
+ st.write(f"DEBUG: Fragment detected: {fragment}") # Temporary debug
39
 
40
  if fragment and not st.session_state.get("hash_migrated"):
41
  # Parse fragment parameters
42
  params = dict(parse_qsl(fragment))
43
+ st.write(f"DEBUG: Parsed params: {params}") # Temporary debug
44
 
45
  if params.get("type") == "recovery" and params.get("access_token"):
46
  # Set query params so existing recovery flow works
 
51
  st.experimental_set_query_params(**params)
52
 
53
  st.session_state["hash_migrated"] = True
54
+ fragment_detected = True
55
  st.rerun()
56
+ except Exception as e:
57
+ st.write(f"DEBUG: Fragment library error: {e}") # Temporary debug
58
+
59
+ # Always run JS fallback for reliability
60
+ if not fragment_detected:
61
  st.markdown(
62
  """
63
  <script>
64
  (function() {
65
+ try {
66
+ const hash = window.location.hash;
67
+ console.log('DEBUG: Hash found:', hash);
68
+ if (hash && hash.length > 1 && !sessionStorage.getItem("hash_migrated")) {
69
+ const query = hash.substring(1);
70
+ const newUrl = window.location.pathname + "?" + query;
71
+ sessionStorage.setItem("hash_migrated", "true");
72
+ window.history.replaceState(null, "", newUrl);
73
+ window.location.reload();
74
+ }
75
+ } catch (e) {
76
+ console.error('Hash migration error:', e);
77
  }
78
  })();
79
  </script>