Login persistence with Streamlit's built-in authentication on browser refresh?

Hi everyone,

I’m exploring the built-in user authentication feature in Streamlit (using st.login(), st.experimental_user). I have a question regarding the user experience when refreshing the browser.

Specifically, if a user has successfully logged into my Streamlit application using this feature, will they need to log in again after refreshing the page in their browser? Or is the login state maintained across refreshes?

I would really appreciate any insights from those who have experience using this feature.

Thank you!

A manual refresh of the browser page starts a new Streamlit session, so they will not be logged in with that new session. However, depending on how you have the connection configured, they may be able to reuse the cookie from their previous login (e.g. calling st.login() may log them straight in from the cookie instead of prompting them for credentials).

1 Like

Hi mathcatsand,

Thank you for your response! Could you please outline the method to implement what you mentioned? Specifically, how can I configure the connection to reuse the cookie so that users don’t need to log in again after a browser refresh? Does this require users to use a specific browser, such as Google Chrome, Edge, or Safari?

Additionally, could you guide me on how to achieve this? Would it be simpler to use Streamlit’s built-in authentication, or should I consider using another library for authentication to handle this scenario more effectively?

Looking forward to your advice!

-Edit- I misremembered something.

Actually, by default, if someone refreshes their browser (without having specifically logged out), they should just be logged in as they were before. The Streamlit cookie is detected and used by default at the beginning of a new Session. I just tested and confirmed using the setting from the Google auth tutorial. If I login then refresh the page, I’m still logged in.