New Component: st-login-form to create a user login form connected to a Supabase DB in 2 lines of code!

Hey all! :wave:

I have created a new component st_login_form that lets you create a user login form connected to a Supabase DB in just 2 lines of code!

:computer: UI

The login form collapses after login to free screen-space.

:computer: Demo app

Open in Streamlit

:construction: Installation

  1. Install st-login-form
pip install st-login-form
  1. Create a Supabase project as mentioned here
  2. Create a table to store the usernames and passwords. The table name and column names can be as per your choice.
CREATE TABLE users (
    username text not null default ''::text,
    password text not null,
    constraint users_pkey primary key (username),
    constraint users_username_key unique (username),
    constraint users_password_check check (
      (
        length(
          trim(
            both
            from
              password
          )
        ) > 1
      )
    ),
    constraint users_username_check check (
      (
        length(
          trim(
            both
            from
              username
          )
        ) > 1
      )
    )
  ) tablespace pg_default;
  1. Follow the rest of the steps from here to connect your Streamlit app to Supabase

:pen: Usage

login_form() sets session_state["authenticated"] to True if the login is successful, session_state["username"] to the username or new or existing user, and to None for guest login.

Returns the initialized supabase.Client instance to let you interact with the databse downstream in the script.

import streamlit as st

from streamlit_login import login_form

client = login_form()

if st.session_state["authenticated"]:
    if st.session_state["username"]:
        st.success(f"Welcome {st.session_state['username']}")
    else:
        st.success("Welcome guest")
else:
    st.error("Not authenticated")

See demo in Streamlit

:bouquet: This is my first streamlit-component, and my first python package, so bouquets and brickbats are very welcome. Thanks! :pray:

4 Likes

That’s such a useful Streamlit component!

Thanks for sharing it with us @SiddhantSadangi! :raised_hands:

Note: worth sharing on Supabase’s forums too! :wink:

Charly

1 Like

Thanks @Charly_Wargnier :hugs:

I’ve just shared it on Supabase’s forums too: Streamlit Login Form | Made with Supabase.
Thanks for the suggestion :slight_smile:

1 Like

Great stuff! Thanks @SiddhantSadangi! :pray:

I’ve added “st-login-form” to my requirements.txt on github and then copy/pasted the form but I’m getting this error:

ModuleNotFoundError: No module named ‘streamlit_login’

Am I using the wrong thing for my requirements.txt file? Sorry for the dumb question, I’m new to coding and have a ton to learn still.

Hello @paulcarl ,

Thanks for bringing this to my attention.

The package name mentioned in the form is incorrect, it should be st_login_form instead of streamlit_login

Can you try the below snippet to see if it works?

import streamlit as st

from st_login_form import login_form

client = login_form()

if st.session_state["authenticated"]:
    if st.session_state["username"]:
        st.success(f"Welcome {st.session_state['username']}")
    else:
        st.success("Welcome guest")
else:
    st.error("Not authenticated")

I am not able to edit the original post :frowning:

Thanks a ton for your help! I’ll test it as soon as possible and let you know how it turns out. I bet it will work from the look of things. Thanks again!

My pleasure :slight_smile:

Please let me know if you have any questions or feedback :hugs:

Looks really cool. I will definitely use it for StreamPy

1 Like

Thanks :slight_smile:

Lemme know how it goes, would love to have your feedback!