Closed johnnyb1509 closed 7 months ago
I was too facing the same issue, what solution i got is, we need to use that if condition snippets in every page, as the first time we do authentication, the browser cookies will get updated, hence whenever the same code is running in other pages , it reads that authentication is already done and reads the other details of the logged in user.
I am not sure if it's the best solution but I use st.session_state to keep track of authentication status. Basically on my Welcome page i have this:
if authentication_status:
authenticator.logout('Logout', 'sidebar', key='unique_key')
st.session_state['user_authenticated'] = True
then on all other pages I have this condition that checks if user is authenticated, and if not it stops exectution and prints a warning for the user to go back to welcome page and login:
if not st.session_state['user_authenticated']:
st.warning('Please login on the welcome page')
st.stop()
Hope it helps!
Dear all, if you are using Streamlit-Authenticator with multi-page apps, you will have to recreate the authenticator object on each and every page and invoke the login method as shown below:
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['pre-authorized']
)
authenticator.login()
This is to ensure that when a user hard refreshes the page and the session state variables related to re-authentication are lost, the authenticator object is there to re-initialize them from the cookie saved on the browser.
Hi,
I have a problem when using authentication process for multiple app. Specifically the directory tree as below
In which, inside the
Homepage.py
, I'm using these codeMy
Page1.py
code is as below:At the first stage, the code works properly when standing at
Homepage
and it switchs directly toPage1
if username/password invalid.From
Page1
, there have function to switch to other pages. And the problem occurs when I came toPage1_1
or others pages, then go back toPage1
, at this time it raise an error as belowHow to solve this problem? And how to maintain the state of authenticate for every pages