mkhorasani / Streamlit-Authenticator

A secure authentication module to manage user access in a Streamlit application.
Other
1.63k stars 254 forks source link

Streamlit 1.32.1+ with streamlit_antd_components issue #183

Open wyzdic opened 3 months ago

wyzdic commented 3 months ago

Streamlit-Authenticator (0.32, 0.33) streamlit_antd_components (0.3.2) In streamlit 1.32.0 the code runs very stably, when I update to a later version of streamlit (including the latest 1.37), streamlit-authenticator does not work properly with streamlit_antd_components. When I log in to the main page, the menu menu will not be displayed, and I need to manually refresh it once by clicking the R key on the keyboard. If I refresh the web page, the menu menu will disappear, and I need to reuse the R key to refresh it to be displayed, if I don't use Streamlit-Authenticator, streamlit_antd_components work fine, I removed all the other redundant code, leaving only the most basic part to reproduce the problem, do you encounter the same problem? Here's the code I reproduced:

` import streamlit as st import streamlit_authenticator as stauth import streamlit_antd_components as sac import yaml from yaml.loader import SafeLoader

st.set_page_config()

with open('config/config.yaml', encoding='utf-8') as file: config = yaml.load(file, Loader=SafeLoader)

authenticator = stauth.Authenticate( config['credentials'], config['cookie']['name'], config['cookie']['key'], config['cookie']['expiry_days'], config['preauthorized'], ) if not st.session_state["authentication_status"]: login_in = authenticator.login( location='main', ) if st.session_state["authentication_status"]: with st.sidebar: menu_select = sac.menu( [ sac.MenuItem('Home', icon='house-fill'), sac.MenuItem('update', icon='calendar2-range-fill', tag=[sac.Tag('New', color='red')]), sac.MenuItem('database', icon='file-earmark-font-fill'), ], open_all=False, height=680, indent=20, index=1, key='menu_select', size='md', )

`

wyzdic commented 3 months ago

https://discuss.streamlit.io/t/after-installing-streamlit-authenticator-and-logging-in-sidebar-menu-desappears-when-reloading-browser-other-components-remain/65304

Same issue here, using streamlit-option-menu

wyzdic commented 2 months ago

After actual testing, I found out that it was extra_streamlit_components component that caused the problem, I tried to comment out the extra_streamlit_components related code in Streamlit-Authenticator, the problem never happened again when the program was running, can I change the package of cookie management to fix the problem?

wyzdic commented 2 months ago

Update: I found a temporary solution Modify Streamlit_Authenticator/models/cookie_model.py Comment: # self.token = self.cookie_manager.get(self.cookie_name) Modified to (streamlit==1.37) if st.context.cookies.get("stauth_cookie"): self.token = st.context.cookies["stauth_cookie"] It's working fine now

mkhorasani commented 2 months ago

Update: I found a temporary solution Modify Streamlit_Authenticator/models/cookie_model.py Comment: # self.token = self.cookie_manager.get(self.cookie_name) Modified to (streamlit==1.37) if st.context.cookies.get("stauth_cookie"): self.token = st.context.cookies["stauth_cookie"] It's working fine now

I considered doing this myself and perhaps I will implement it, but until Streamlit has a native way to read and write cookies, then I cannot fully replace the streamlit cookies manager.

wyzdic commented 2 months ago

I guess this works as a temporary solution until streamlit natively supports cookies, maybe the st.context in streamlit 1.37 means that this day won't be too long?