cryogenic22 commited on
Commit
19ff2de
·
verified ·
1 Parent(s): a7f541f

Create auth/handler.py

Browse files
Files changed (1) hide show
  1. src/ui/auth/handler.py +37 -0
src/ui/auth/handler.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Authentication handling for the application"""
2
+ import streamlit as st
3
+ from typing import Optional, Dict
4
+
5
+ def check_authentication() -> bool:
6
+ """Check if user is authenticated"""
7
+ if 'user' not in st.session_state:
8
+ show_login()
9
+ return False
10
+ return True
11
+
12
+ def show_login() -> None:
13
+ """Display login form"""
14
+ st.title("🔐 Login")
15
+
16
+ with st.form("login_form"):
17
+ # Default to test@example.com for easy testing
18
+ email = st.text_input("Email", value="test@example.com")
19
+ submitted = st.form_submit_button("Login")
20
+
21
+ if submitted:
22
+ authenticate_user(email)
23
+
24
+ def authenticate_user(email: str) -> None:
25
+ """Authenticate user and set up session"""
26
+ db_service = st.session_state.services['db']
27
+
28
+ user = db_service.get_user_by_email(email)
29
+ if user:
30
+ st.session_state.user = user
31
+ # Get user's accounts immediately after login
32
+ accounts = db_service.get_user_accounts(user['id'])
33
+ st.session_state.user_accounts = accounts
34
+ st.success(f"Welcome back, {user['name']}!")
35
+ st.rerun()
36
+ else:
37
+ st.error("Invalid email. Please try again.")