Skip to content

Commit 0fdf7f1

Browse files
adnanqaopsgitbook-bot
authored andcommitted
GITBOOK-186: Supabase SDK documentation
1 parent cc68a8b commit 0fdf7f1

File tree

6 files changed

+114
-4
lines changed

6 files changed

+114
-4
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
* [Supabase](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/README.md)
8181
* [Supabase PostgreSQL](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-postgresql.md)
8282
* [Supabase Assets API](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-assets-api.md)
83-
* [Supabase Management API](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-management-api.md)
8483
* [Supabase RealTime](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-realtime.md)
84+
* [Supabase OAuth](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-oauth.md)
8585
* [PostgreSQL](connect-your-data/data-sources-in-lowcoder/sql-databases/postgresql.md)
8686
* [Microsoft SQL Server](connect-your-data/data-sources-in-lowcoder/sql-databases/microsoft-sql-server.md)
8787
* [Oracle](connect-your-data/data-sources-in-lowcoder/sql-databases/oracle.md)

docs/connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,22 @@ Supabase is an open-source backend-as-a-service (BaaS) platform that provides de
2020
* Storing and managing media files like images, videos, or documents.
2121
* Rapidly building and scaling applications without setting up custom backend infrastructure.
2222

23+
### Supabase SDK
24+
25+
We have integrated Supabase SDK to Lowcoder, so that our App Users can directly use it in the apps to its full potential.
26+
27+
Users can use all the functionalities provided by Supabase inside Lowcoder using "supabase" object. e.g. to interact with your Postgres database, listen to database changes, build login and user management functionality, and manage large files.
28+
29+
### Initialising Supabase Client 
30+
31+
Create a new client for use in the browser. You can initialize a new Supabase client using the `createClient()` method.
32+
33+
The Supabase client is your entry point to the rest of the Supabase functionality and is the easiest way to interact with everything Supabase offers within its ecosystem.
34+
35+
```
36+
const supabase_client = supabase.createClient('supabase-project-url', 'public-anon-key')
37+
```
38+
39+
Now, using this "supabase\_client" created above, we will interact with PostgreSQL DB in Supabase, explore Supabase Assets/Storage feature, setup an OAuth and use Supabase RealTime feature. Let's explain these one by one.
40+
2341
Let's explore some of the core features of Supabase, one by one.

docs/connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-assets-api.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,40 @@ Follow the steps below : 
2222
Let's show you how we can use the Supabase Storage feature to Upload and Retrieve data to/from Supabase. 
2323

2424
{% embed url="https://demos.lowcoder.cloud/demo/cm0p82k14000110hfpa1xr8da" %}
25+
26+
All of the above functionalities can be accessed using Supabase SDK as well. 
27+
28+
To create a bucket on Supabase Storage, use following code : 
29+
30+
```
31+
const { data, error } = await supabase
32+
.storage
33+
.createBucket('avatars', {
34+
public: false,
35+
allowedMimeTypes: ['image/png'],
36+
fileSizeLimit: 1024
37+
})
38+
```
39+
40+
To List all the buckets present on Supabase Storage, use following code : 
41+
42+
```
43+
const { data, error } = await supabase
44+
.storage
45+
.getBucket('avatars')
46+
```
47+
48+
To List all files in a specific Bucket, use following code : 
49+
50+
```
51+
const { data, error } = await supabase
52+
.storage
53+
.from('avatars')
54+
.list('folder', {
55+
limit: 100,
56+
offset: 0,
57+
sortBy: { column: 'name', order: 'asc' },
58+
})
59+
```
60+
61+
More details can be found here : [https://supabase.com/docs/reference/javascript/storage-createbucket](https://supabase.com/docs/reference/javascript/storage-createbucket)

docs/connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-management-api.md

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Supabase OAuth
2+
3+
Lowcoder App users can authenticate their app users using the Supabase OAuth feature. It can be accessed through "supabase.auth".
4+
5+
Supabase Auth works with many popular Auth methods, including Social and Phone Auth using third-party providers and the list can be found [https://supabase.com/docs/guides/auth#providers](https://supabase.com/docs/guides/auth#providers) .
6+
7+
In order to Sign up a User through OAuth, we can use the following code :
8+
9+
```
10+
const { data, error } = await supabase.auth.signInWithOAuth({
11+
provider: 'google',
12+
options: {
13+
redirectTo: 'https://example.com/welcome'
14+
}
15+
})
16+
```
17+
18+
We have to set the "Provider" that we need to use for Sign up. But, before running this query , We need to set the details related to OAuth on Supabase and on the Provider side, in this case Google. For setting up OAuth using Google, please follow the instructions written on this link : [https://supabase.com/docs/guides/auth/social-login/auth-google](https://supabase.com/docs/guides/auth/social-login/auth-google)
19+
20+
After successful sign in through OAuth, we can store the OAuth Provider token using following code : 
21+
22+
```
23+
// Register this immediately after calling createClient!
24+
// Because signInWithOAuth causes a redirect, you need to fetch the
25+
// provider tokens from the callback.
26+
27+
supabase.auth.onAuthStateChange((event, session) => {
28+
if (session && session.provider_token) {
29+
window.localStorage.setItem('oauth_provider_token', session.provider_token)
30+
}
31+
})
32+
```
33+
34+
In the following Demo, we have shown how to setup Google OAuth using Supabase SDK : 
35+
36+
{% embed url="https://demos.lowcoder.cloud/demo/cm348a4ma1853533h7m9qp11k" %}
37+
Setting up Google OAuth using Supabase SDK
38+
{% endembed %}
39+

docs/connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-postgresql.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,22 @@ Follow the steps below:
2323

2424
{% embed url="https://demos.lowcoder.cloud/demo/clzmno7d50b0prfaixv9i8nxc" %}
2525

26-
\
26+
All of the above functionalities can be accessed using Supabase SDK as well. 
27+
28+
To fetch data from DB, we can use the Select method on Supabase object. 
29+
30+
```
31+
const { data, error } = await supabase
32+
.from('countries')
33+
.select()
34+
```
35+
36+
To insert data into a Table, use following code. 
37+
38+
```
39+
const { error } = await supabase
40+
.from('countries')
41+
.insert({ id: 1, name: 'Denmark' })
42+
```
43+
44+
More details can be found here : [https://supabase.com/docs/reference/javascript/select](https://supabase.com/docs/reference/javascript/select)

0 commit comments

Comments
 (0)