FauziIsyrinApridal commited on
Commit
063328b
·
1 Parent(s): 5016d5f
Files changed (1) hide show
  1. app/auth.py +44 -7
app/auth.py CHANGED
@@ -34,16 +34,47 @@ def auth_view():
34
 
35
  # --- Password recovery handler (Supabase redirect) ---
36
  # 1) Move hash params to query params on first load, then reload once
37
- components.html(
 
38
  """
39
  <script>
40
  (function () {
41
  try {
42
  var hash = window.location.hash;
43
- // Only act if hash contains params and we haven't migrated
44
  if (hash && hash.length > 1 && !sessionStorage.getItem('hash_migrated')) {
45
  var hashParams = new URLSearchParams(hash.substring(1));
46
  var queryParams = new URLSearchParams(window.location.search);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  var hasParams = false;
49
  hashParams.forEach(function (value, key) {
@@ -53,19 +84,25 @@ def auth_view():
53
 
54
  if (hasParams) {
55
  // Mark as migrated to avoid loops
56
- sessionStorage.setItem('hash_migrated', 'true');
57
  // Build absolute URL (preserve origin + path), clear hash, and REPLACE (no extra reloads)
58
- var newUrl = window.location.origin + window.location.pathname + '?' + queryParams.toString();
59
- window.location.replace(newUrl);
 
 
 
 
 
 
60
  }
61
  }
62
  } catch (e) {
63
- console.error('hash->query migration failed', e);
64
  }
65
  })();
66
  </script>
67
  """,
68
- height=0,
69
  )
70
 
71
  # 2) Read query params for recovery flow
 
34
 
35
  # --- Password recovery handler (Supabase redirect) ---
36
  # 1) Move hash params to query params on first load, then reload once
37
+ # Try in main document first (no iframe), so it can read the top-level hash reliably
38
+ st.markdown(
39
  """
40
  <script>
41
  (function () {
42
  try {
43
  var hash = window.location.hash;
 
44
  if (hash && hash.length > 1 && !sessionStorage.getItem('hash_migrated')) {
45
  var hashParams = new URLSearchParams(hash.substring(1));
46
  var queryParams = new URLSearchParams(window.location.search);
47
+ var hasParams = false;
48
+ hashParams.forEach(function (value, key) {
49
+ queryParams.set(key, value);
50
+ hasParams = true;
51
+ });
52
+ if (hasParams) {
53
+ sessionStorage.setItem('hash_migrated', 'true');
54
+ var newUrl = window.location.origin + window.location.pathname + '?' + queryParams.toString();
55
+ window.location.replace(newUrl);
56
+ }
57
+ }
58
+ } catch (e) {
59
+ console && console.warn && console.warn('main-doc hash->query failed', e);
60
+ }
61
+ })();
62
+ </script>
63
+ """,
64
+ unsafe_allow_html=True,
65
+ )
66
+ components.html(
67
+ """
68
+ <script>
69
+ (function () {
70
+ try {
71
+ // In iframe context, read and write via parent to ensure access to top-level URL
72
+ var w = window.parent || window;
73
+ var hash = w.location.hash;
74
+ // Only act if hash contains params and we haven't migrated
75
+ if (hash && hash.length > 1 && !w.sessionStorage.getItem('hash_migrated')) {
76
+ var hashParams = new URLSearchParams(hash.substring(1));
77
+ var queryParams = new URLSearchParams(w.location.search);
78
 
79
  var hasParams = false;
80
  hashParams.forEach(function (value, key) {
 
84
 
85
  if (hasParams) {
86
  // Mark as migrated to avoid loops
87
+ w.sessionStorage.setItem('hash_migrated', 'true');
88
  // Build absolute URL (preserve origin + path), clear hash, and REPLACE (no extra reloads)
89
+ var newUrl = w.location.origin + w.location.pathname + '?' + queryParams.toString();
90
+ w.location.replace(newUrl);
91
+ // Fallback after a short delay in case replace is ignored
92
+ setTimeout(function(){
93
+ if (w.location.hash) {
94
+ w.location.href = newUrl;
95
+ }
96
+ }, 250);
97
  }
98
  }
99
  } catch (e) {
100
+ console.error('iframe hash->query migration failed', e);
101
  }
102
  })();
103
  </script>
104
  """,
105
+ height=1,
106
  )
107
 
108
  # 2) Read query params for recovery flow