Data from multiple pages showing at same time

I am running the app locally.

st.session_state.authenticated = False
st.set_page_config(layout=“wide”)

def main():

# Check if user is authenticated
if st.session_state.authenticated:
    show_main_pages()
else:
    show_login_page()

def show_login_page():

>     st.title("Log In")
>     email = st.text_input('Email Address')
>     password = st.text_input('Password', type='password')
>     if st.button("Sign In"):
>         response = sign_in2(email, password)
>         st.write(response)
>         if response == "Signed in successfully":  # Update session state if login successful
>             st.session_state.authenticated = True
>             main()

The session state authentication is initialised as False and the main() function dictates that in such cases the login page should show. So when I boot up Streamlit, I am shown the log in page.

After successfuly signing in, Streamlit redirects to the main pages, however, the issue is that the login page still shows at the very top (the show_main_pages() content is shown below it).

How can I stop the login page data showing after I have successfully logged in?

I have tried to replace the last line (“main()”) of show_login_page() with “show_main_pages()” itself directly but this results in same issue.

Hi @Bahir_Zaheri

When using if st.session_state.authenticated this implied that if st.session_state.authenticated is True, can you try:

if st.session_state.authenticated == False:
    show_main_pages()
else:
    show_login_page()

I understand that the below implies if X is true, but that is what I intended? Why wouldn’t this work? I am trying to say that if there is authentication then go to the main pages and if there isn’t, then (ELSE) show login page.

if st.session_state.authenticated:

by the way, in your code suggestion, the show_main_pages() and show_login_page() should be in each other’s place right?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.