Streamlit Authentication - authenticator.login('main', 'Login') always returning None

Hi,

I’m new to streamlit and I’m trying to put some authentication into my app. I seem to always be getting None back in my code. I understand that it gives a None value when it first loads but for some reason even after I enter a username & password and click Login it returns None.

Just wondering if I’m doing something incorrect or if Streamlit 1.42 has stopped supporting the Authenticator.login and we need to setup an OIDC login workflow.
Please let me know.

Here is my code:
import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader

Load credentials

with open(‘./credentials.yml’) as file:
config = yaml.load(file, SafeLoader)

Create an authentication object

authenticator = stauth.Authenticate(
config[‘credentials’],
config[‘cookie’][‘name’],
config[‘cookie’][‘key’],
config[‘cookie’][‘expiry_days’]
)

Add login widget

result = authenticator.login(‘main’, ‘Login’)
print(result)
if result is None:
# Handle the case when no login data is returned
st.error(“Login failed or no login attempt made.”)
else:
name, authentication_status, username = result
# Handle authentication status
if authentication_status:
st.write(f’Welcome {name}')
# Your app code here
authenticator.logout(‘Logout’, ‘main’)
elif authentication_status == False:
st.error(‘Username/password is incorrect’)
elif authentication_status == None:
st.warning(‘Please enter your username and password’)

Here is my YAML sample_file:
credentials:
usernames:
jsmith:
email: jsmith@gmail.com
name: John Smith
password: abc # To be replaced with hashed password
ksmith:
email: ksmith@gmail.com
name: Kelly Smith
password: def # To be replaced with hashed password
cookie:
expiry_days: 0
key: some_signature_key
name: some_cookie_name

Thanks.