Persisting session_state after st.login (i.e. a page refresh)?

Hello!

I am wondering if there is any way to save some information through a page refresh?

I am currently trying to build an app where I have the user input some information and then click the login button (using the native st.login). But that causes a page refresh when coming back to the app, which means the session_state is lost and I can’t access the previously inputted information anymore.

I do have a database setup, but the data I want to save is linked to a particular user and I don’t have any identifiable information to save it with before the login so I have no idea how I could retrieve it after.

I have been thinking about cookies, but I don’t know if they’d be a good use case for that and/or if they work correctly on Streamlit cloud (from my internet search it seems like it’s not really supported).

I was wondering if anyone had any ideas?

Why not have the user login first and then have them enter the info you need as the first step before allowing them to use app?

This way you can save the entered into to session_state or database.

For sure that’d solve everything! I might just do that if I can’t find a solution. My current hope is to have the user fill out the input form before logging in, as I expect that to increase engagement (a quick Google search tells me that this concept seems to be called “gradual engagement”)

Just get rid of the form and use the plain fields to get the login that way you wouldn’t lose the values.

The issue with form is it will rerun the app on submit and you will lose the session state

Thanks.

I’m not using a form or plain fields though, I’m using the new st.login function (and native auth in general, introduced in 1.42). It makes the process of setting up authentication a lot easier, but it requires a reload of the page (as opposed to a rerun), which is why session_state is lost (which it wouldn’t be with just a rerun).

Edit: Sorry, rereading my messages I realize where the confusion might have come from. When I talk about an “input form” in my previous message, I mean the inputs I am gathering from the user for an ML model my app is using, not anything to do with the log in itself. I don’t know if it’s clearer?

1 Like