mgbam commited on
Commit
41b05bb
·
verified ·
1 Parent(s): 1310b61

Update services/auth.py

Browse files
Files changed (1) hide show
  1. services/auth.py +12 -2
services/auth.py CHANGED
@@ -1,12 +1,15 @@
 
 
1
  import streamlit as st
2
  from streamlit_authenticator import Authenticate
3
  from config.settings import settings
4
  from repositories.user_repo import UserRepo
5
  from models.db import init_db
6
 
7
- # Initialize DB tables
8
  init_db()
9
 
 
10
  user_repo = UserRepo(settings.database_url)
11
 
12
  def init_auth():
@@ -23,15 +26,22 @@ def init_auth():
23
  cookie_expiry_days=1,
24
  )
25
 
 
26
  authenticator = init_auth()
27
 
28
  def require_login():
 
 
 
 
29
  login_result = authenticator.login(location="sidebar")
30
- # Bail out if login form didn't render a result
31
  if login_result is None:
32
  st.stop()
33
 
34
  name, authentication_status, username = login_result
35
  if not authentication_status:
36
  st.stop()
 
 
 
37
  return username
 
1
+ # services/auth.py
2
+
3
  import streamlit as st
4
  from streamlit_authenticator import Authenticate
5
  from config.settings import settings
6
  from repositories.user_repo import UserRepo
7
  from models.db import init_db
8
 
9
+ # 1) Ensure DB tables exist
10
  init_db()
11
 
12
+ # 2) User repo
13
  user_repo = UserRepo(settings.database_url)
14
 
15
  def init_auth():
 
26
  cookie_expiry_days=1,
27
  )
28
 
29
+ # 3) Instantiate authenticator
30
  authenticator = init_auth()
31
 
32
  def require_login():
33
+ # 🔧 Initialize logout flag so login() can read it
34
+ if 'logout' not in st.session_state:
35
+ st.session_state['logout'] = False
36
+
37
  login_result = authenticator.login(location="sidebar")
 
38
  if login_result is None:
39
  st.stop()
40
 
41
  name, authentication_status, username = login_result
42
  if not authentication_status:
43
  st.stop()
44
+
45
+ # 🛑 Render the logout button once logged in
46
+ authenticator.logout("Logout", location="sidebar")
47
  return username