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!
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")
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!
This is a very useful component you have created. First time I implemented it, it worked well. Now when I am trying to use it in an application to serve as the landing page from where the user will proceed to the actual work-flow, I am getting the error as below -
Blockquote
Uncaught app exception
Traceback (most recent call last):
File “C:\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 541, in run_script
exec(code, module.dict)
File “xxx:\xxx\xxxxx\xxxxxxxx\xxxxx\demo.py”, line 43, in
client = st_login_form.login_form(user_tablename=“users”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\st_login_form_init.py", line 141, in login_form
data, _ = (
^^^^^^^
ValueError: too many values to unpack (expected 2)
Thanks a ton for early response!!
The component has started working again. Didn’t really understand the reason. But one thing that I can report it that it started working after I deleted the earlier deployment of Streamlit Cloud.
In any case my application has starting working locally. Though I have yet to deploy on Cloud.
While deploying on Streamlit Cloud, I am getting same error again - “ValueError: too many values to unpack (expected 2)”.
I had forked the main branch which has has the version v0.2.1
So, after the success in local deployment, I am once again stuck in the Cloud deployment.
Please help in correcting this error.
Blockquote
[16:34:05] Python dependencies were installed from /mount/src/st_login_form/requirements.txt using pip.
Check if streamlit is installed
Streamlit is already installed
[16:34:07] Processed dependencies!
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.
2023-10-10 16:35:01.323 HTTP Request: GET https://zkavxipxbwlaljqaskng.supabase.co/rest/v1/users?select=username%2C%20password&username=eq.xxxxxxxxx&password=eq.xxxxxxxxxx “HTTP/1.1 200 OK”
2023-10-10 16:35:01.325 Uncaught app exception
Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 565, in _run_script
exec(code, module.dict)
File “/mount/src/st_login_form/demo.py”, line 7, in
client = login_form()
File “/home/adminuser/venv/lib/python3.9/site-packages/st_login_form/init.py”, line 141, in login_form
data, _ = (
ValueError: too many values to unpack (expected 2)
Blockquote
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.