as-cle-bert commited on
Commit
2a1575f
1 Parent(s): 13b40cc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +162 -14
README.md CHANGED
@@ -1,14 +1,162 @@
1
- ---
2
- title: Streamlit Supabase Auth Ui
3
- emoji: 📚
4
- colorFrom: red
5
- colorTo: gray
6
- sdk: streamlit
7
- sdk_version: 1.39.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Seamless Supabase authentication for seamless Streamlit apps
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Streamlit Supabase Auth Ui
3
+ emoji:
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.39.0
8
+ app_file: app.py
9
+ pinned: true
10
+ license: mit
11
+ short_description: Seamless Supabase authentication for seamless Streamlit apps
12
+ thumbnail: >-
13
+ https://cdn-uploads.huggingface.co/production/uploads/65e330e7edc2f7306e252448/LQ-Rke_7K1o4hHwUWNVzv.png
14
+ ---
15
+
16
+ <div align="center">
17
+ <h1>streamlit_supabase_auth_ui</h1>
18
+ <h2>Seamless Supabase authentication for seamless Streamlit apps</h2>
19
+ </div>
20
+ <br>
21
+ <div align="center">
22
+ <img src="https://img.shields.io/github/languages/top/AstraBert/streamlit_supabase_auth_ui" alt="GitHub top language">
23
+ <img src="https://img.shields.io/github/commit-activity/t/AstraBert/streamlit_supabase_auth_ui" alt="GitHub commit activity">
24
+ <img src="https://img.shields.io/pypi/pyversions/streamlit-supabase-auth-ui" alt="Static Badge">
25
+ <img src="https://img.shields.io/pypi/dm/streamlit-supabase-auth-ui" alt="PyPI Downloads">
26
+ <img src="https://img.shields.io/badge/Release-v0.0.0-purple" alt="Static Badge">
27
+ <br>
28
+ <br>
29
+ <img src="https://raw.githubusercontent.com/AstraBert/streamlit_supabase_auth_ui/main/imgs/supabase_logo.png" alt="Supabase Logo" width="100" style="margin-right: 10px;">
30
+ <img src="https://raw.githubusercontent.com/AstraBert/streamlit_supabase_auth_ui/main/imgs/plus.jpg" alt="plus" width="30" style="margin-right: 10px;">
31
+ <img src="https://raw.githubusercontent.com/AstraBert/streamlit_supabase_auth_ui/main/imgs/streamlit_logo.jpg" alt="Streamlit Logo" width="100">
32
+ </div>
33
+
34
+
35
+
36
+ ### Purpose and Inspiration
37
+
38
+ [**Streamlit**](https://streamlit.io/) 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.
39
+
40
+ The most popular of them, [streamlit-authenticator](https://github.com/mkhorasani/Streamlit-Authenticator)and [streamlit_login_auth_ui](https://github.com/GauriSP10/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).
41
+
42
+ We decided to build a new authentication UI, based on [Gauri Prabhakar](https://github.com/GauriSP10)'s login interface, that combines the power of [**Supabase**](https://supabase.co)PostgreSQL databases with the seamless frontend components from **Streamlit**, connecting it also to the e-mail notifications service offered by [**Courier**](https://www.courier.com/) .
43
+
44
+ The UI has login, user registration, password reset and 'forgot password' functionalities, as well as a logout one.
45
+
46
+ So, let's get started!🚀
47
+
48
+ ### Third party services
49
+
50
+ #### 1. Supabase
51
+
52
+ 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.
53
+
54
+ In order to do that, we:
55
+
56
+ 1. Create a [Supabase account](https://supabase.com/dashboard/sign-up)
57
+ 2. Go to [our dashboard](https://supabase.com/dashboard/projects)
58
+ 3. Create a new project
59
+ 4. Go to `Project Settings > API` and copy `URL` under `Project URL` and `anon public` key under `Project API Keys`
60
+ 5. Copy the URL to `supa_url` and the ANON key to `supa_key` in [`.streamlit/secrets.toml`](./.streamlit/secrets.toml)
61
+ 6. Open SQL editor on Supabase and execute the following command:
62
+ ```sql
63
+ CREATE TABLE user_authentication (
64
+ id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
65
+ username VARCHAR(255) DEFAULT NULL,
66
+ password VARCHAR(255) DEFAULT NULL,
67
+ email VARCHAR(255) DEFAULT NULL,
68
+ name VARCHAR(255) DEFAULT NULL,
69
+ created_at TIMESTAMP DEFAULT NOW()
70
+ );
71
+ ```
72
+
73
+ #### 2. Courier
74
+
75
+ We want to send email notifications basically for two reasons:
76
+
77
+ - Welcome our new users upon registration
78
+ - Send them reset passwords when they want to change their old/lost password
79
+
80
+ To do so, we use the already mentioned Courier, and so we need to:
81
+
82
+ 1. [Sign up](https://app.courier.com/signup) to Courier
83
+ 2. Create a new workspace
84
+ 3. Enable an e-mail service provider. The easiest and cheapest choice is **Gmail**: you only need to specify the Gmail account for which you want to activate the service, which will also be one that will send all the emails.
85
+ 4. Retrieve the **authorization token** from `Settings > API Keys`
86
+ 5. Copy the authorization token and place it under `courier_auth_token` in [.streamlit/secrets.toml](./.streamlit/secrets.toml)
87
+
88
+ ### Create your application
89
+
90
+ #### 1. Build from source
91
+
92
+ We now want to create our Streamlit application with Supabase authentication and user management, and, in order to do so, we:
93
+
94
+ 1. Clone this repository and go inside it:
95
+ ```bash
96
+ git clone https://github.com/AstraBert/streamlit_supabase_auth_ui.git
97
+ cd streamlit_supabase_auth_ui
98
+ ```
99
+ 2. Create a python virtual environment and activate it:
100
+ ```bash
101
+ python3 -m venv streamlit-app
102
+ source streamlit-app/bin/activate
103
+ ```
104
+ 3. Install all the required dependencies:
105
+ ```bash
106
+ python3 -m pip install -r requirements.txt
107
+ ```
108
+ 4. Modify [`.streamlit/secrets.toml`](./.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 beforehand
109
+ 6. Run the application:
110
+ ```bash
111
+ python3 -m streamlit run app.py
112
+ ```
113
+
114
+ 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:
115
+
116
+ ```python
117
+ import streamlit as st
118
+ from .streamlit_supabase_auth_ui.widgets import __login__
119
+
120
+ __login__obj = __login__(auth_token = st.secrets["courier_auth_token"],
121
+ company_name = "YOUR-ORG-NAME",
122
+ width = 200, height = 250,
123
+ logout_button_name = 'Logout', hide_menu_bool = False,
124
+ hide_footer_bool = False,
125
+ lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
126
+
127
+ LOGGED_IN= __login__obj.build_login_ui()
128
+
129
+ if LOGGED_IN == True:
130
+
131
+ ### Your Streamlit app here!
132
+ ```
133
+
134
+ #### 2. Get PyPi package
135
+
136
+ We made `streamlit-supabase-auth-ui` also a python package available on PyPi, that you can find [here](https://pypi.org/project/streamlit-supabase-auth-ui/).
137
+
138
+ To get it, it is sufficient to run:
139
+
140
+ ```bash
141
+ python3 -m pip install streamlit-supabase-auth-ui
142
+ ```
143
+
144
+ And the installation process will take care of mounting all the necessary dependencies✅
145
+
146
+ You can then simply import the package in your code:
147
+
148
+ ```python
149
+ import streamlit as st
150
+ from streamlit_supabase_auth_ui.widgets import __login__
151
+
152
+ __login__obj = __login__(auth_token = st.secrets["courier_auth_token"],
153
+ company_name = "YOUR-ORG-NAME",
154
+ width = 200, height = 250,
155
+ logout_button_name = 'Logout', hide_menu_bool = False,
156
+ hide_footer_bool = False,
157
+ lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
158
+ ```
159
+
160
+ ### Live demo
161
+
162
+ Find a live demo on [HuggingFace Spaces](https://huggingface.co/spaces/as-cle-bert/streamlit-supabase-auth-ui).