I am building a multi-page app with user authentication. The problem is that the log in screen does not disappears after a successful log in. The log in screen remains in the UI until i switch pages. Then the log in screen disappears. I want it to disappears directly after successful log in.
code
import pandas as pd
import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader
with open("config.yaml") as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config["credentials"],
config["cookie"]["name"],
config["cookie"]["key"],
config["cookie"]["expiry_days"],
config["preauthorized"],
)
name, authentication_status, username = authenticator.login(key="Login", location="main")
if authentication_status:
with st.sidebar:
authenticator.logout("Logout", "sidebar")
st.write(f"Welcome *{name}*")
# Add four additional pages to the sidebar
pages = ["Page 1", "Page 2", "Page 3", "Page 4"]
page = st.sidebar.selectbox("Choose a page", pages)
if page == "Page 1":
st.title("Page 1")
st.write("This is Page 1")
# Load the appropriate file based on the authenticated user
file_path = config['credentials']['usernames'][username]['file_path_table']
df = pd.read_excel(file_path)
# Display the dataframe
st.write(df)
elif page == "Page 2":
st.title("Page 2")
st.write("This is Page 2")
elif page == "Page 3":
st.title("Page 3")
st.write("This is Page 3")
elif page == "Page 4":
st.title("Page 4")
st.write("This is Page 4")
elif authentication_status is False:
st.error('Username/password is incorrect')
elif authentication_status is None:
st.warning('Please enter your username and password')
else:
st.empty()