diff --git a/ui/admin.py b/ui/admin.py index 1dab822c5..438f0f0a9 100644 --- a/ui/admin.py +++ b/ui/admin.py @@ -1,11 +1,13 @@ """ Admin sets proxy url + allowed email subdomain """ +from dotenv import load_dotenv +load_dotenv() import streamlit as st -import base64 +import base64, os # Replace your_base_url with the actual URL where the proxy auth app is hosted -your_base_url = 'http://localhost:8501' # Example base URL +your_base_url = os.getenv("BASE_URL") # Example base URL # Function to encode the configuration def encode_config(proxy_url, allowed_email_subdomain): diff --git a/ui/app.py b/ui/app.py index 6b469bc37..5d49d45f8 100644 --- a/ui/app.py +++ b/ui/app.py @@ -1,8 +1,10 @@ """ Routes between admin, auth, keys pages """ +from dotenv import load_dotenv +load_dotenv() import streamlit as st -import base64, binascii +import base64, binascii, os from admin import admin_page from auth import auth_page from urllib.parse import urlparse, parse_qs @@ -44,7 +46,7 @@ if page_param: try: # Try to decode the page_param from base64 if is_base64(page_param): - auth_page() + auth_page(redirect_url=f"{os.getenv('BASE_URL')}/{page_param}") else: st.error("Unknown page") except Exception as e: diff --git a/ui/auth.py b/ui/auth.py index e5e226a8a..d94e30ffb 100644 --- a/ui/auth.py +++ b/ui/auth.py @@ -5,6 +5,8 @@ Uses supabase passwordless auth: https://supabase.com/docs/reference/python/auth Remember to set your redirect url to 8501 (streamlit default). """ +import logging +logging.basicConfig(level=logging.DEBUG) import streamlit as st from dotenv import load_dotenv load_dotenv() @@ -17,14 +19,18 @@ key: str = os.environ.get("SUPABASE_KEY") supabase: Client = create_client(url, key) -def sign_in_with_otp(email: str): - data = supabase.auth.sign_in_with_otp({"email": email}) +def sign_in_with_otp(email: str, redirect_url: str): + data = supabase.auth.sign_in_with_otp({"email": email, + "options": { + "email_redirect_to": redirect_url + }}) + print(f"data: {data}") # Redirect to Supabase UI with the return data st.write(f"Please check your email for a login link!") # Create the Streamlit app -def auth_page(): +def auth_page(redirect_url: str): st.title("User Authentication") # User email input @@ -32,4 +38,4 @@ def auth_page(): # Sign in button if st.button("Sign In"): - sign_in_with_otp(email) + sign_in_with_otp(email, redirect_url=redirect_url)