FauziIsyrinApridal commited on
Commit
5016d5f
·
1 Parent(s): 0a5edbb
Files changed (1) hide show
  1. app/auth.py +28 -32
app/auth.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import base64
3
  import streamlit as st
4
  from app.db import supabase
 
5
 
6
 
7
  def auth_view():
@@ -33,43 +34,38 @@ def auth_view():
33
 
34
  # --- Password recovery handler (Supabase redirect) ---
35
  # 1) Move hash params to query params on first load, then reload once
36
- st.markdown(
37
  """
38
  <script>
39
- (function(){
40
- // Check if we have hash parameters and haven't migrated yet
41
- const hash = window.location.hash;
42
- if (hash && hash.length > 1 && !sessionStorage.getItem('hash_migrated')) {
43
- // Remove the # and parse as URLSearchParams
44
- const hashParams = new URLSearchParams(hash.substring(1));
45
- const queryParams = new URLSearchParams(window.location.search);
46
-
47
- // Copy all hash params to query params
48
- let hasParams = false;
49
- for (const [key, value] of hashParams.entries()) {
50
- queryParams.set(key, value);
51
- hasParams = true;
52
- }
53
-
54
- if (hasParams) {
55
- // Build new URL with query params
56
- const newUrl = window.location.pathname + '?' + queryParams.toString();
57
-
58
- // Mark as migrated to prevent infinite loops
59
- sessionStorage.setItem('hash_migrated', 'true');
60
-
61
- // Replace current URL and clear hash
62
- window.history.replaceState(null, '', newUrl);
63
- window.location.hash = '';
64
-
65
- // Reload to let Streamlit process the new query params
66
- window.location.reload();
67
  }
 
 
68
  }
69
  })();
70
  </script>
71
  """,
72
- unsafe_allow_html=True,
73
  )
74
 
75
  # 2) Read query params for recovery flow
@@ -177,7 +173,7 @@ def auth_view():
177
  # Prefer explicit env, then generic site URL, then localhost for dev
178
  redirect_url = os.getenv(
179
  "SUPABASE_EMAIL_REDIRECT",
180
- os.getenv("NEXT_PUBLIC_SITE_URL", "http://localhost:8501"),
181
  )
182
  supabase.auth.sign_up({
183
  "email": r_email,
@@ -198,7 +194,7 @@ def auth_view():
198
  # Prefer explicit env, then generic site URL, then localhost for dev
199
  redirect_url = os.getenv(
200
  "SUPABASE_EMAIL_REDIRECT",
201
- os.getenv("NEXT_PUBLIC_SITE_URL", "http://localhost:8501"),
202
  )
203
  supabase.auth.reset_password_for_email(f_email, {"redirect_to": redirect_url})
204
  st.success("Email reset password telah dikirim. Periksa kotak masuk Anda.")
 
2
  import base64
3
  import streamlit as st
4
  from app.db import supabase
5
+ import streamlit.components.v1 as components
6
 
7
 
8
  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) {
50
+ queryParams.set(key, value);
51
+ hasParams = true;
52
+ });
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
 
173
  # Prefer explicit env, then generic site URL, then localhost for dev
174
  redirect_url = os.getenv(
175
  "SUPABASE_EMAIL_REDIRECT",
176
+ os.getenv("NEXT_PUBLIC_SITE_URL", "https://yozora721-pnp-chatbot-v1.hf.space/"),
177
  )
178
  supabase.auth.sign_up({
179
  "email": r_email,
 
194
  # Prefer explicit env, then generic site URL, then localhost for dev
195
  redirect_url = os.getenv(
196
  "SUPABASE_EMAIL_REDIRECT",
197
+ os.getenv("NEXT_PUBLIC_SITE_URL", "https://yozora721-pnp-chatbot-v1.hf.space/"),
198
  )
199
  supabase.auth.reset_password_for_email(f_email, {"redirect_to": redirect_url})
200
  st.success("Email reset password telah dikirim. Periksa kotak masuk Anda.")