mkhorasani / Streamlit-Authenticator

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

Speed up process of authentication #152

Open Morgan-DCL opened 2 months ago

Morgan-DCL commented 2 months ago

Hi! First off, thanks so much for this amazing feature!

I use it in every project I'm involved with. It’s easy to use and implement.

However, I’ve encountered an issue: there are no tips, workarounds, or even mentions regarding the delay when applying the login() function. The login process takes a few seconds.

I'm currently working on a project that requires multiple pages. As explained, it's necessary to apply the login() method on all these pages to maintain the connection through the cookie. But these few seconds of wait every time we switch pages significantly slow down the process.

Is there a way to speed up this process? How can I keep the cookie without having to apply login() every time?

To give more detail: I have several pages where I only apply login() on the home page, then I simply pass on the authentication status. If this status is False, I redirect the user to the home page. I use other pages hidden with st_pages, accessible via query_params by clicking on a Linkcolumn from st.data_editor. When I click, opening the hidden page and logging in takes time. Without logging in, the opening is instantaneous. Since I open and close these pages frequently, the cumulative waiting time becomes a problem...

Any ideas on how to work around these delays?

Thanks! Morgan

mkhorasani commented 2 months ago

Dear @Morgan-DCL, thank you for reaching out! This is an issue raised by other developers as well and while I don't have a solution just yet, it is definitely something in my backlog and I hope to address it in a timely manner. Another feature that I'm currently working on is an un-rendered login method #149, which will smoothen re-authentication on sub-pages. In the meantime please stay tuned and hopefully, there will be a fix in the near future!

sbslee commented 1 day ago

Hi @mkhorasani,

Thank you so much for developing and maintaining such a wonderful package. I use it extensively for all of my projects.

Unfortunately, like others, I have encountered a situation where my Streamlit app takes forever to load the login page (more than 5 minutes). The credentials contain information for about 500 people.

I understand that you are currently working on improving the speed. However, I am keen to understand the situation better. Could you kindly let us know which step(s) are responsible for this long wait? I saw in #164 that maybe disabling cookies could help. Does this mean that the major bottleneck is related to cookies? I'm asking these questions because, in the worst-case scenario, I will have to come up with my own authenticator (presumably much simpler but faster).

mkhorasani commented 1 day ago

Hi @sbslee, thank you for reaching out and your kind message! Yes absolutely, I promise this issue will be resolved in the next version. It is associated with the automated hashing feature that hashes plain-text passwords. I will refactor it so that it runs in a different way to avoid taking so much time. Please stay tuned.