Skip to content

Commit 232b57b

Browse files
committed
handle the logout functionality correctly
Signed-off-by: lochanpaudel <lochanpaudel10@gmail.com>
1 parent 39cf5e0 commit 232b57b

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/mvt/app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import streamlit as st
2-
from menu import menu
2+
from menu import menu, handle_logout
33
from database import create_connection, create_table, create_prompts_table, get_user, insert_user
44
from homepage import gethomepage
55
import os
@@ -162,5 +162,7 @@ def show_credentials_error():
162162
create_prompts_table(conn)
163163
conn.close()
164164

165-
# Show menu
165+
# Show menu and logout button
166+
if "user_type" in st.session_state and st.session_state.user_type is not None:
167+
handle_logout()
166168
menu()

src/mvt/menu.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
def handle_logout():
44
"""Handle logout action and state cleanup"""
55
if st.sidebar.button("Log out"):
6-
st.session_state['user_type'] = None
7-
st.session_state['username'] = None
8-
st.session_state.pop('first_login', None)
6+
for key in list(st.session_state.keys()):
7+
del st.session_state[key]
98
st.logout()
109
st.switch_page("app.py")
1110

1211
def authenticated_menu():
13-
# Show logout button at the top of sidebar
14-
handle_logout()
15-
1612
# Show a navigation menu for authenticated users
1713
st.sidebar.page_link("pages/chatbot.py", label="AIFAQ ChatBot")
1814
if st.session_state.user_type in ["admin"]:

0 commit comments

Comments
 (0)