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

Authenticator, User Registeration status #128

Closed MrVolts closed 5 months ago

MrVolts commented 5 months ago

I have found that the user is shown to have registered before even pressing the button: image

My code:

import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader

with open('config.yaml') as file:
    config = yaml.load(file, Loader=SafeLoader)

# Create an instance of the Streamlit-Authenticator
authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['preauthorized']
)

def update_config_file():
    # Write the updated configuration back to the YAML file
    with open('config.yaml', 'w') as file:
        yaml.dump(config, file, default_flow_style=False)

try:
    if authenticator.register_user(preauthorization=False):
        st.success('User registered successfully')
            # Update the configuration file after successful registration
        update_config_file()
except Exception as e:
    st.error(e)
mkhorasani commented 5 months ago

Hi @MrVolts, which version of Streamlit-Authenticator are you using?

yeraypabon commented 5 months ago

I'm actually having the same problem. The Streamlit-Authenticator that I have is 0.3.1 via pip.

mkhorasani commented 5 months ago

Apologies, the example in the readme is not correct, the correct way to use the register_user widget should be as follows:

try:
    email_of_registered_user, username_of_registered_user, name_of_registered_user = authenticator.register_user(preauthorization=False)
    if email_of_registered_user:
        st.success('User registered successfully')
except Exception as e:
    st.error(e)

Please let me know if this helps.