Streamlit Authentication - Page navigation

I have been using streamlit-authenticator in a multipage streamlit app,
whenever I reload the page its going to login and shows the login screen and then navigates back to the original page.
I don’t want this to happen. Please help me find a solution for this.

Hi @Naveen_Chekkapalli

Perhaps you can try the login app that @blackary had created https://app-app.streamlit.app/

Here’s the corresponding repo for the above mentioned app GitHub - blackary/streamlit-login

Sorry for not mentioning the issue clearly,
I am using cookies to store the user session when user logs in, using cookie manager. But when I reload the page, the application goes to the login page and the authentication happens there and coming back to the original(target) page.

I’ve tried using auth._check_cookie() in the target page

if 'authentication_status' not in st.session_state or not st.session_state['authentication_status']:
    auth._check_cookie()
    if 'authentication_status' not in st.session_state or not st.session_state['authentication_status']:
        # go to login page
    
else:
    # target page

authentication status in st.session_state is set to True in _check_cookie function, but here the app still goes back to the login page.

If I use sleep(10) after the auth._check_cookie(), it is working.

Please help me resolve this

Hey @Naveen_Chekkapalli,

We fixed a couple issues for st.switch_page() in the latest version 1.31.1, might try that and see if it helps.

If not, any chance you could share a longer app snippet or point to a repo to help us repro this issue? I’m curious to take a look.

Thanks!

hey, i am facing a similar issue. when i launch my app , it first shows the login page and then navigates back to the original page, could you help me out? this is my code snippet which i think is the point of that reload, or login page appearing first and navigating back to original page. ps: my login credentials do get saved in cookies

        menu = ["Login","Register"]
        # Sidebar Image
        # st.sidebar.image('images/company-logo.png',width=200)
        choice = st.sidebar.selectbox("Menu",menu)
        if choice == "Login": #login and register in different pages
            authenticator.login('Login', 'main')
        elif choice == "Register":
                register_user_form = st.form('Register user')
                register_user_form.subheader("Register")
                new_email = register_user_form.text_input('Email')
                new_name = register_user_form.text_input('Name')
                new_password = register_user_form.text_input('Password', type='password')
                new_password_repeat = register_user_form.text_input('Repeat password', type='password')
                if register_user_form.form_submit_button('Register'):
                    user_document = collection.find_one({"email": new_email})
                    if len(new_email)  and len(new_name) and len(new_password) > 0:
                        if not user_document:
                            if new_password == new_password_repeat:         
                                _register_credentials(new_email, new_name, new_password)
                                st.success('User registered successfully')
                            else:
                                st.error('Passwords do not match')
                        else:
                            st.error('Email already taken')
                    else:
                        st.error('Please enter an email, name, and password')

    if st.session_state["authentication_status"] is True:
        print("session_state after authentication_status is true :",st.session_state)
        email = st.session_state["email"]```