Spaces:
Sleeping
Sleeping
File size: 1,181 Bytes
19ff2de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
"""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.") |