Initial commit

Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: Michael Cartner <32543275+michaelcartner@users.noreply.github.com>
This commit is contained in:
Eric Tuvesson
2023-09-05 12:08:55 +02:00
commit 53f0d6320e
2704 changed files with 76354 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
---
title: Supabase
hide_title: true
---
# Supabase
This prefab gives you a few components that allows you to connect to Supabase and manage user authentication.
> This prefab is built by [Guillaume Maison](https://twitter.com/gmaison) and [Rico Trevisan](https://twitter.com/RicoTrevisan). Please show them some love if you find this prefab useful.
<div className="ndl-image-with-background l">
![](/library/prefabs/supabase/thumb.png)
</div>
## Included components
### Base Components
- **[Supabase - Setup Client](components/setup-client)**: Sets up the Supabse SDK client to access your supabase instance. Must be placed in your projects home component.
- **[Supabase - Example Request](components/supabase-request-example)**: An example on how to fetch data from a table in Supabase.
### User Components
- **[Supabase Sign Up](components/supabase-sign-up)**: Signs up a new user.
- **[Supabase Log In](components/supabase-log-in)**: Logs in a user.
- **[Supabase Log Out](components/supabase-log-out)**: Logs out a user.
- **[Supabase Send Password Reset](components/supabase-send-password-reset)**: Sends a link to reset user password.
- **[Supabase Send Magic Link](components/supabase-send-magic-link)**: Sends a login link without password.
- **[Supabase Resend Confirmation](components/supabase-resend-confirmation)**: Resend a signup confirmation email when validating sign up by email
- **[Supabase Fetch Current User Auth](components/supabase-fetch-current-user-auth)**: Retrieves the auth data of the currently logged in user and saves it to a global `currentUser` object.
- **[Supabase Fetch Current User Profile Data](components/supabase-fetch-current-user-profile-data)**: Retrieves the non-auth user data of the currently logged in user and saves it to a global `currentUser` object.
- **[Supabase Update Current User Auth](components/supabase-update-current-user-auth)**: Updates auth data for the currently logged in user, both in Supabase and the `currentUser` object.
- **[Supabase Update Current User Profile Data](components/supabase-update-current-user-profile-data)**: Updates user data for the currently logged in user, both in Supabase and the `currentUser` object.
### Pages
You will also find a couple of pages that allow you to quickly get up and running with all user features.
Set the `Supabase Example App Root` as your home component for a quick start on all routing.
## Quickstart
First, drop a **Supabase Setup Client** in your project home component and input your `Supabase URL` and `Supabase Anon Key` in its Property Panel. Then, open the **Projects Settings** sidebar and find the `Head Code` input. Add the following at the top:
```html
<script type="module">
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.22.0';
window.createClient = createClient;
</script>
```
Lastly, you need to connect the `Did Mount` output of your root Group node to the `Do` input of the `Supabase - Setup Client` like so:
<div className="ndl-image-with-background l">
![](/library/prefabs/supabase/setup.png)
</div>
This will set everything up and allow you to use all of the other Supabase components.
You can use an **[Object](/nodes/data/object/object-node)** node set to the id `currentUser` to get all the user data (if a user is logged in).
You can use the **[Supabase Fetch Current User Auth](components/supabase-update-current-user-auth)** component to check if the user is logged in. If the user is already authenticated from a previous session, this session is retrieved, the user is considered logged in, and the component outputs `true` on its `Logged In` output and in the `currentUser` Noodl object.
Use the **[Supabase - Fetch Current User Profile Data](components/supabase-update-current-user-profile-data)** to trigger a data fetch and refresh the non-auth data in the `currentUser` object.

View File

@@ -0,0 +1,83 @@
---
title: Setup Client
hide_title: true
---
# Setup Client
This component is used to initialize Supabase Client and set it up to query your Supabase backend.
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/setup-node.png)
</div>
> Please note that you need to place one instance of this component in your project home component, set the default values of the `Supabase URL` and `Supabase Anon Key`, and connect the the `Did Mount` output of your root Group node to the `Do` input like in the image above.
## Values from Supabase
You can find the required URL and Anon Key by logging into your Supabase instance, navigating to `Settings -> API`, and look for the Project URL and Project API Keys sections:
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/keys.png)
</div>
## Setup
First, drop a **Supabase Setup Client** in your project home component and input your `Supabase URL` and `Supabase Anon Key` in its Property Panel. Then, open the **Projects Settings** sidebar and find the `Head Code` input. Add the following at the top:
```html
<script type="module">
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.22.0';
window.createClient = createClient;
</script>
```
Lastly, you need to connect the `Did Mount` output of your root Group node to the `Do` input of the `Supabase - Setup Client` like so:
<div className="ndl-image-with-background l">
![](/library/prefabs/supabase/setup.png)
</div>
This will set everything up and allow you to use all of the other Supabase components.
## Global Variables
The Supabase prefab sets up a couple of global Noodl variables for you to work with:
### Supabase_userProfileTableName
This variable is a string and must be set to the name of the table containing the `user_profile` data in your Supabase instance. Its primary key must be named `id` and be of the same type as `auth.users.id`.
### currentUser
This variable contains all the data for the currently logged in user. It contains 4 fields:
- `currentUser.loggedIn`: a boolean containing the current logged in state
- `currentUser.auth`: an object with all the authentication data for current User
- `currentUser.session`: an object with all the session data for current User
- `currentUser.profile`: an object with all the data coming from the user profile
## Inputs
| Data | Description |
| --------------------------------------------------- | --------------------------------------------------------------------------------- |
| <span className="ndl-data">Supabase URL</span> | Found in your `Supabase Instance -> Settings -> API -> Project URL section`. |
| <span className="ndl-data">Supabase Anon Key</span> | Found in your `Supabase Instance -> Settings -> API -> Project API Keys section`. |
| Signals | Description |
| -------------------------------------- | --------------------------------------------- |
| <span className="ndl-signal">Do</span> | Starts the initialization of Supabase Client. |
## Outputs
| Signals | Description |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the Supabase client initialization succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when the Supabase client initialization failed with an error message in the console. |

View File

@@ -0,0 +1,32 @@
---
title: Fetch Current User Auth
hide_title: true
---
# Fetch Current User Auth
This component is used to send a request to Supabase and retrieve all authorisation data on the currently logged in user. After a success it updates the `auth`, `session` and `loggedIn` properties on the Noodl object with the id `currentUser`.
<div className="ndl-image-with-background">
![](/library/prefabs/supabase/fetchauth.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Signals | Description |
| -------------------------------------- | -------------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the fetch request call. |
## Outputs
| Data | Description |
| ------------------------------------------- | --------------------------------------------------- |
| <span className="ndl-data">Logged In</span> | A boolean that holds the users current login state. |
| Signals | Description |
| ---------------------------------------- | --------------------------------------------- |
| <span className="ndl-signal">Done</span> | Sends a signal when the request has finished. |

View File

@@ -0,0 +1,34 @@
---
title: Fetch Current User Profile Data
hide_title: true
---
# Fetch Current User Auth
This component is used to send a request to Supabase and retrieve all profile data on the currently logged in user. After a success it updates the `profile` property on the Noodl object with the id `currentUser`.
<div className="ndl-image-with-background">
![](/library/prefabs/supabase/fetchdata.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Signals | Description |
| -------------------------------------- | -------------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the fetch request call. |
## Outputs
| Data | Description |
| --------------------------------------- | ---------------------------------------------------- |
| <span className="ndl-data">Error</span> | Outputs the the error message if the request failed. |
| Signals | Description |
| ------------------------------------------------ | -------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal if the request is successful. |
| <span className="ndl-signal">Failure</span> | Sends a signal if the request has failed. |
| <span className="ndl-signal">No User Data</span> | Sends a signal if there is no user data to be retrieved. |

View File

@@ -0,0 +1,44 @@
---
title: Log In
hide_title: true
---
# Log In
This component is used to log a user in. Once email address and password are set, the sign up is triggered after a signal is sent to the `Do` input.
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/login.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## On success
When a user has successfully been logged in the **Log In** component will create a Noodl Object with the id `currentUser`. This object contains all the user data. You can use the **[Supabase - Fetch Current User Profile Data](/library/prefabs/supabase/components/supabase-update-current-user-profile-data)** to refresh all non-auth data for the user.
A successful login will also trigger a `Supabase User Logged In` event. You can hook into to this event anywhere in your app using a [Receive Event](/nodes/events/receive-event/) node.
## Inputs
| Data | Description |
| ------------------------------------------ | ------------------------------------------ |
| <span className="ndl-data">Email</span> | Sets the email used to log in the user. |
| <span className="ndl-data">Password</span> | Sets the password used to log in the user. |
| Signals | Description |
| -------------------------------------- | ------------------------ |
| <span className="ndl-signal">Do</span> | Triggers the login call. |
## Outputs
| Data | Description |
| --------------------------------------- | ---------------------------------------------------------- |
| <span className="ndl-data">Error</span> | The error sent back after a failed login call to Supabase. |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,39 @@
---
title: Log In
hide_title: true
---
# Log In
This component is used to log a user out.
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/logout.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## On success
When a user has successfuly been logged out the **Log Out** component will empty the Noodl Object with the id `currentUser`.
A successful log out will also trigger a `Supabase User Logged Out` event. You can hook into to this event anywhere in your app using a [Receive Event](/nodes/events/receive-event/) node.
## Inputs
| Signals | Description |
| -------------------------------------- | ------------------------ |
| <span className="ndl-signal">Do</span> | Triggers the login call. |
## Outputs
| Data | Description |
| --------------------------------------- | ---------------------------------------------------------- |
| <span className="ndl-data">Error</span> | The error sent back after a failed logout call to supabase |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,28 @@
---
title: Request Example
hide_title: true
---
# Request Example
This demo component executes a request to your Supabase instance.
:::note
In itself, this component is not usable. It is just here to show you an example of how to create such a Request component based on the Supabase Client API.
:::
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/request-example.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly make requests to Supabase.
## Making requests
The advanced nature of Supabase means that you need to write some code to make requests to your backend. Luckily their API is well documented, and can even be generated using the Noodl AI `/Function` command.
No matter if you write the calls yourself or generate them, it could be good to familiarize youself with their simple database functions. You can find them [here](https://supabase.com/docs/reference/javascript/select).
It is also a good idea to familiarize yourself with building custom Components in Noodl, as this will increase the requests reusability and maintainability. [This guide](/docs/guides/user-interfaces/components) teaches you how to build visual components, but the same concepts apply to logic components (that will be the most useful for Supabase requests).

View File

@@ -0,0 +1,33 @@
---
title: Resend Confirmation
hide_title: true
---
# Resend Confirmation
This component is used to resend a signup confirmation email if the initial email was not received or expired.
<div className="ndl-image-with-background l">
![](/library/prefabs/supabase/resendconfirmation.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Data | Description |
| --------------------------------------- | -------------------------------------------- |
| <span className="ndl-data">Email</span> | The email to send the confirmation email to. |
| Signals | Description |
| -------------------------------------- | ------------------------------------ |
| <span className="ndl-signal">Do</span> | Triggers the send confirmation call. |
## Outputs
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,38 @@
---
title: Send Magic Link
hide_title: true
---
# Send Magic Link
This component is used to send a login link that doesnt require a password.
<div className="ndl-image-with-background l">
![](/library/prefabs/supabase/magic-link.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Data | Description |
| --------------------------------------- | ------------------------------------ |
| <span className="ndl-data">Email</span> | The email to send the magic link to. |
| Signals | Description |
| -------------------------------------- | ---------------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the magic link send call. |
## Outputs
| Data | Description |
| --------------------------------------- | ----------------------------------------------------------- |
| <span className="ndl-data">Data</span> | The response data from a successful request. |
| <span className="ndl-data">Error</span> | The error sent back after a failed logout call to Supabase. |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,38 @@
---
title: Send Password Reset
hide_title: true
---
# Send Password Reset
This component is used to send a password reset email to the provided email.
<div className="ndl-image-with-background l">
![](/library/prefabs/supabase/send-password-reset.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Data | Description |
| --------------------------------------- | ---------------------------------------- |
| <span className="ndl-data">Email</span> | The email to send the password reset to. |
| Signals | Description |
| -------------------------------------- | --------------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the password reset call. |
## Outputs
| Data | Description |
| --------------------------------------- | ----------------------------------------------------------- |
| <span className="ndl-data">Data</span> | The response data from a successful request. |
| <span className="ndl-data">Error</span> | The error sent back after a failed logout call to Supabase. |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,40 @@
---
title: Sign Up
hide_title: true
---
# Sign Up
This component is used to sign up a user into Supabase. Once email address and password are set, the sign up is triggered after a signal is sent to the `Do` input.
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/sign-up.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Data | Description |
| ------------------------------------------ | ------------------------------------------- |
| <span className="ndl-data">Email</span> | Sets the email used to sign up the user. |
| <span className="ndl-data">Password</span> | Sets the password used to sign up the user. |
| Signals | Description |
| -------------------------------------- | ------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the signup call. |
## Outputs
| Data | Description |
| ---------------------------------------------- | ------------------------------------------------------------------ |
| <span className="ndl-data">Data</span> | The data that is sent back by the supabase client. |
| <span className="ndl-data">Error</span> | The error sent back after a failed signup call to supabase. |
| <span className="ndl-data">Is Connected</span> | `true`/`false` depending on if the user is connected after signup. |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,39 @@
---
title: Update Current User Auth
hide_title: true
---
# Update Current User Auth
This component is used to to update the current logged in users email and password.
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/updateauth.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Signals | Description |
| -------------------------------------- | -------------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the fetch request call. |
| Data | Description |
| ------------------------------------------ | ----------------------------------- |
| <span className="ndl-data">Email</span> | The email you want to update to. |
| <span className="ndl-data">Password</span> | The password you want to update to. |
## Outputs
| Data | Description |
| --------------------------------------- | -------------------------------------------------------------- |
| <span className="ndl-data">Data</span> | The response sent back after a successful request to Supabase. |
| <span className="ndl-data">Error</span> | The error sent back after a failed request to Supabase. |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |

View File

@@ -0,0 +1,37 @@
---
title: Update Current User Data
hide_title: true
---
# Update Current User Data
This component is used to to update the current logged in users profile data.
<div className="ndl-image-with-background xl">
![](/library/prefabs/supabase/updateprofile.png)
</div>
> Please note that [Supabase Client](/library/prefabs/supabase/components/setup-client/) needs to be set up in your app before you can properly use this component.
## Inputs
| Signals | Description |
| -------------------------------------- | -------------------------------- |
| <span className="ndl-signal">Do</span> | Triggers the fetch request call. |
| Data | Description |
| -------------------------------------- | --------------------------------------------------- |
| <span className="ndl-data">Data</span> | A JS object containing the data you want to update. |
## Outputs
| Data | Description |
| --------------------------------------- | ------------------------------------------------------- |
| <span className="ndl-data">Error</span> | The error sent back after a failed request to Supabase. |
| Signals | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------- |
| <span className="ndl-signal">Success</span> | Sends a signal when the request succeeded. |
| <span className="ndl-signal">Failure</span> | Sends a signal when an error occurred, and logs an error message in the console. |