Spaces:
Sleeping
Sleeping
| """Authentication handling for the application""" | |
| import streamlit as st | |
| from typing import Optional, Dict | |
| def check_authentication() -> bool: | |
| """Check if user is authenticated""" | |
| if 'user' not in st.session_state: | |
| show_login() | |
| return False | |
| return True | |
| def show_login() -> None: | |
| """Display login form""" | |
| st.title("🔐 Login") | |
| with st.form("login_form"): | |
| # Default to test@example.com for easy testing | |
| email = st.text_input("Email", value="test@example.com") | |
| submitted = st.form_submit_button("Login") | |
| if submitted: | |
| authenticate_user(email) | |
| def authenticate_user(email: str) -> None: | |
| """Authenticate user and set up session""" | |
| db_service = st.session_state.services['db'] | |
| user = db_service.get_user_by_email(email) | |
| if user: | |
| st.session_state.user = user | |
| # Get user's accounts immediately after login | |
| accounts = db_service.get_user_accounts(user['id']) | |
| st.session_state.user_accounts = accounts | |
| st.success(f"Welcome back, {user['name']}!") | |
| st.rerun() | |
| else: | |
| st.error("Invalid email. Please try again.") |