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

Code in readme fails to login #115

Closed fxavier-maf closed 5 months ago

fxavier-maf commented 5 months ago

Hi,

I'm using package version 0.2.5 and the code from the README page. When I run the app, I am repeatedly getting the following error:

Traceback (most recent call last):
  File "<path>/env/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)
  File "<path>/login.py", line 28, in <module>
    name, auth_status, username = authenticator.login(max_concurrent_users=1)
  File "<path>/env/lib/python3.9/site-packages/streamlit_authenticator/authenticate.py", line 251, in login
    self._check_cookie()
  File "<path>/env/lib/python3.9/site-packages/streamlit_authenticator/authenticate.py", line 133, in _check_cookie
    st.session_state['name'] = self.credentials['usernames'][self._get_username('id', self.token['id'])]['name']
KeyError: False

I cleared the cache multiple-times but the issue persists. Has anyone faced this issue before ?

mkhorasani commented 5 months ago

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

fxavier-maf commented 5 months ago

Thanks @mkhorasani. But I think I'm already doing that and the errors shows despite that:

name, auth_status, username = authenticator.login(max_concurrent_users=1)
print(config)
with open('config.yaml', 'w') as file:
    yaml.dump(config, file, default_flow_style=False)
print(config)

The print(config) shows that the content of the files are the same. Shouldn't they be different ?

mkhorasani commented 5 months ago

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

fxavier-maf commented 5 months ago

It works now, @mkhorasani. Thank you!