Hey all!
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!
UI
The login form collapses after login to free screen-space.
Demo app
Installation
- Install
st-login-form
pip install st-login-form
- Create a Supabase project as mentioned here
- 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;
- Follow the rest of the steps from here to connect your Streamlit app to Supabase
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")
This is my first streamlit-component, and my first python package, so bouquets and brickbats are very welcome. Thanks!