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

self._check_cookie() fails #114

Closed dohleml-tu closed 5 months ago

dohleml-tu commented 5 months ago

Hello,

I encountered a bug with the streamlit.authenticator that was not present in the past. When we try to resume a users session the check for cookies fails with the following error:

KeyError: False
Traceback:

File "/usr/local/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)
File "/app/src/og_app/OG_app.py", line 29, in <module>
    authenticator, authorized, username, name = widget_authenticate_and_check(
File "/app/src/og_app/utils_auth.py", line 55, in widget_authenticate_and_check
    name, authorized, username = authenticator.login(location=auth_loc)
File "/usr/local/lib/python3.10/site-packages/streamlit_authenticator/authenticate.py", line 246, in login
    self._check_cookie()
File "/usr/local/lib/python3.10/site-packages/streamlit_authenticator/authenticate.py", line 128, in _check_cookie
    st.session_state['name'] = self.credentials['usernames'][self._get_username('id', self.token['id'])]['name']

We only updated our package dependencies and did not change anything regarding the authentication process in our app itself. So we assume at is bug.

We are using python 3.10 streamlit 1.30.0 streamlit-authenticator 0.2.5

mkhorasani commented 5 months ago

Dear @dohleml-tu, please make sure to save changes to the config file after every widget as shown below:

with open('../config.yaml', 'w') as file:
    yaml.dump(config, file, default_flow_style=False)

This is to ensure that the new 'ID' field that is being automatically generated will be saved to the config file.

mkhorasani commented 5 months ago

Dear @dohleml-tu, I have decided to axe Streamlit-Authenticator v0.2.5 and instead replace it with v0.3.1 to resolve this issue. Please download this latest version.