Streamlit Supabase Auth Ui
Seamless Supabase authentication for seamless Streamlit apps
Streamlit is a popular backend-to-frontend app development framework for python, and over the years several solutions have been developed to tackle user authentication and management for Streamlit apps.
The most popular of them, streamlit-authenticator and streamlit_login_auth_ui, although offering several advanced functionalities and dynamic UIs, lack a reliable backend, database-centered user management (which is generally performed through local files).
We decided to build a new authentication UI, based on Gauri Prabhakar's login interface, that combines the power of Supabase PostgreSQL databases with the seamless frontend components from Streamlit, connecting it also to the e-mail notifications service offered by Courier.
The UI has login, user registration, password reset and 'forgot password' functionalities, as well as a logout one.
So, let's get started!🚀
We will need a Supabase account to build a project, retrieve its URL and ANON key and create a user_authentication database, that will connect our UI to the backend, database-centered user-management.
In order to do that, we:
Project Settings > API and copy URL under Project URL and anon public key under Project API Keyssupa_url and the ANON key to supa_key in .streamlit/secrets.tomlCREATE TABLE user_authentication (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
username VARCHAR(255) DEFAULT NULL,
password VARCHAR(255) DEFAULT NULL,
email VARCHAR(255) DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
We want to send email notifications basically for two reasons:
To do so, we use the already mentioned Courier, and so we need to:
Settings > API Keys courier_auth_token in .streamlit/secrets.tomlWe now want to create our Streamlit application with Supabase authentication and user management, and, in order to do so, we:
git clone https://github.com/AstraBert/streamlit_supabase_auth_ui.git
cd streamlit_supabase_auth_ui
python3 -m venv streamlit-app
source streamlit-app/bin/activate
python3 -m pip install -r requirements.txt
.streamlit/secrets.toml with the Supabase project URL (supa_url), Supabase project ANON key (supa_key) and Courier authentication token (courier_auth_token) we retrieved beforehandpython3 -m streamlit run app.py
You can obviously customize the Streamlit application as much as you want, you will only need to integrate this peace of code to make the Supabase-based auth to work:
import streamlit as st
from .streamlit_supabase_auth_ui.widgets import __login__
__login__obj = __login__(auth_token = st.secrets["courier_auth_token"],
company_name = "YOUR-ORG-NAME",
width = 200, height = 250,
logout_button_name = 'Logout', hide_menu_bool = False,
hide_footer_bool = False,
lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
LOGGED_IN= __login__obj.build_login_ui()
if LOGGED_IN == True:
### Your Streamlit app here!
We made streamlit-supabase-auth-ui also a python package available on PyPi, that you can find here.
To get it, it is sufficient to run:
python3 -m pip install streamlit-supabase-auth-ui
And the installation process will take care of mounting all the necessary dependencies✅
You can then simply import the package in your code:
import streamlit as st
from streamlit_supabase_auth_ui.widgets import __login__
__login__obj = __login__(auth_token = st.secrets["courier_auth_token"],
company_name = "YOUR-ORG-NAME",
width = 200, height = 250,
logout_button_name = 'Logout', hide_menu_bool = False,
hide_footer_bool = False,
lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
Find a live demo on HuggingFace Spaces.
Seamless Supabase authentication for seamless Streamlit apps
Hello, congratulations on your work.
Is it possible to customize and translate the menu names and inputs into another language?
Hi! Yes, the code is open and you can modify it for your projects :)
If you want to change the language of the components, you just need to modify the widget.py script, i.e. https://github.com/AstraBert/streamlit_supabase_auth_ui/blob/main/streamlit_supabase_auth_ui/widgets.py
Thanks for the answer. =)
I have one more question, I'm getting this message in the app:
st.cache is deprecated and will be removed soon. Please use one of Streamlit's new caching commands, st.cache_data or st.cache_resource. More information in our docs.
Note: The behavior of st.cache was updated in Streamlit 1.36 to the new caching logic used by st.cache_data and st.cache_resource. This might lead to some problems or unexpected behavior in certain edge cases.
I looked in the code where you are calling st.cache and I couldn't find it. Could you help me find it, please?
I did not specify any configuration, but I'm pretty sure we could play around with Supabase and set a login/logout status for the user (like saying: the user last logged in at time X and logged out at time Y; if Y > X, then the user can login in again, else they cannot).
If you want, I can put it in the roadmap for the next release of the package: then I would ask you to open an issue here: https://github.com/AstraBert/streamlit_supabase_auth_ui/issues so that I can add it to the milestone for v0.1.0 :)
Cool, it would be great to have this update for the library. I'll do it, I'll post it there. Thanks again. I'm creating a micro SaaS in Streamlit and this component of yours is helping me a lot.
Hi there, just wanted to reach out also here, so that if people see our conversation know that this feature has been integrated: you can now find it in the v0.1.0 of the package, already installable via pip.
Have fun!
Thanks for this, made my day