mkhorasani / Streamlit-Authenticator

A secure authentication module to validate user credentials in a Streamlit application.
Apache License 2.0
1.38k stars 229 forks source link

Login needs 2x click (authentication_status possible error) #95

Closed yash2mehta closed 3 months ago

yash2mehta commented 8 months ago

Hi, I think the authentication_status is not benig able to persist across multiple pages. Please see this page for more information (source code + issues):

https://discuss.streamlit.io/t/login-button-random-behavior/54909

@mkhorasani can you please help, would be greatly appreciated

mkhorasani commented 8 months ago

Hi, @yash2mehta sure will take a look and hopefully fix any issues in the next release. Thanks.

mkhorasani commented 3 months ago

Dear @yash2mehta, 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.