Streamlit-Authenticator
Streamlit-Authenticator copied to clipboard
Refreshing page does not use cookie to re-authenticate
Hello,
I have a multipage app and am having re-authentication problems when refreshing pages. I have updated to 0.3.2, but this problem occurred before and still remains.
Problem 1: refreshing on same page as authentication occurs
I log in on the home.py
page (entry point), and that works fine. I can see the cookie gets stored in the browser devtools. If I refresh the page, I can see the st.session_state start off initially blank for a fraction of a second, then populate with the username
, logout
, and authentication_status
attributes all set to NULL
. I can see, however, that the init
attribute contains the cookie key-value pair, so at least I can use that. Should the authentication_status
and username
attributes be NULL
? I've been using custom logic that checks if the cookie key-value pair exists inside st.session_state.init
, and if it does, to count the user as "logged in", but it seems like extra work. Intuitively, I'd expect the authentication_status
and username
attributes to use the cookie and have proper values.
Problem 2: refreshing on another page
After logging in on home.py
entry point page (and whether I refresh that page or not), if I navigate to another page, say report.py
, I can see the authentication_status
and username
attributes are correctly set. So I can easily use those to determine authentication status for my application. But if I then refresh while on report.py
, the session state becomes a completely blank dictionary, not even including the cookie key-value pair. So now, how is my application meant to know if the user is logged in or not? I can see the cookie in the browser devtools, but not in st.session_state.init
, as st.session_state
is empty.
What is the recommended way to handle authentication status across multiple pages and taking into account reloads? Reloads are actually very prevalent, especially if someone wants to bookmark a specific page of my application. Whenever they open that bookmark, it is akin to a reload, and the st.session_state
is empty and my application doesn't know if they're logged in.
Thanks in advance!