Sign-in authenticator for cloud-deployed streamlit app

  1. I am running the deployed cloud-streamlit app on Community Cloud by Streamlit.io
  2. The problem is I do not know how to use Streamlit authenticator for user info in Streamlit secrets for resetting the password and new user creating account
    I hope you can give me a snippet code or show me some crucial steps.
    Thank you!!

Hi @Phong_Le_Hoang,

Have you checked out the streamlit-authenticator’s README? It includes instructions on creating a password reset widget here and a new user registration widget here.

1 Like

I have read the instruction in Readme page. So, is it the same way I should do yaml file when i push it upload to github.repo to deploy cloud app authen?

Dear Caroline,
Thank you for your time,
I have tried following the steps in the guide, but I am still unable to implement the new registration and forgot password features using streamlit-authenticator.

I have created a private GitHub repo, and I have a config.yaml file containing login information. My Python code for creating the login functionality is as follows:

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

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

# Edit and add new functionality to config file
with open('config.yaml', 'w') as file:
    yaml.dump(config, file, default_flow_style=False)

# Create the authenticator object
authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['preauthorized']
)

# Render the login widget
name, authentication_status, username = authenticator.login('Login', 'main')

# Process login results
if st.session_state["authentication_status"]:
    authenticator.logout('Logout', 'main')
    st.write(f'Welcome *{st.session_state["name"]}*')
    st.title('Some content')
elif st.session_state["authentication_status"] == False:
    st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] == None:
    st.warning('Please enter your username and password')

# Register new user
try:
    if authenticator.register_user('Register user', preauthorization=False):
        st.success('User registered successfully')
except Exception as e:
    st.error(e)

# Show config file
if st.button('Show file config.yaml'):
    config

When I attempt to register a new user using the widget, I am unable to save the new registration information into the config.yaml file in the GitHub repo.

Here is the link to the app I deployed on the cloud: https://dangnhap01.streamlit.app/

Please give me advise!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.