Dependencies

Supabase

Supabase is used for the Superagent UI, it provides the database, Authentication with well know auth providers and a Bucket for file storage.

Website - supabase.com


Github - supabase/supabase

Setting up supabase with Docker

For quickly trying out supabase with Superagent, a docker compose example is provided in the folder libs/.docker/ui/supabase/ For a production setup refer to the official documentation on self hosting supabase.


Run supabase with docker compose

  1. cd into the supabase example folder

    1
    cd libs/.docker/ui/supabase/
    
  2. Copy the .env.example file into a .env file

    1
    cp .env.example .env
    
  3. In the example .env file many of the variables are pre-configured to work with Superagent locally with docker compose, out of the box. It is advised to review and change all of the keys and passwords in the .env file.

    • Supabase has a guide and a tool for generating new values for JWT_SECRET, ANON_KEY and SERVICE_ROLE_KEY in their official docs. Review your POSTGRES_PASSWORD and DASHBOARD_PASSWORD too.
    • Copy any changed values over to the docker .env file for Superagent.
    1
    2
    3
    4
    # libs/.docker/.env
    JWT_SECRET=<JWT_SECRET from supabase .env>
    NEXT_PUBLIC_SUPABASE_ANON_KEY=<ANON_KEY from supabase .env>
    SUPABASE_DB_URL=postgresql://postgres:<POSTGRES_PASSWORD from supabase .env>@supabase-db:5433/postgres
    
  4. Setup Authentication provider for use with Superagent UI.

    • The following external auth providers are supported by Supabase and in turn by Superagent - apple, azure, bitbucket, discord, facebook, figma, github, gitlab, google, keycloak, linkedin, notion, spotify, slack, twitch, twitter and workos
    • An example set of variables is provided below for GITHUB auth, for others simply change the name of the provider in each variable name. e.g GOTRUE_EXTERNAL_AZURE_ENABLED. Refer to each providers own documentation for information on setting up auth.
    • See the section Github Authentication Setup below for steps to setup Github Authentication via your github account.
    1
    2
    3
    4
    5
    6
    # libs/.docker/ui/supabase/.env
    GOTRUE_EXTERNAL_GITHUB_ENABLED=true
    GOTRUE_EXTERNAL_GITHUB_CLIENT_ID=<GITHUB - CLIENT_ID>
    GOTRUE_EXTERNAL_GITHUB_SECRET=<GITHUB - CLIENT_SECRET>
    GOTRUE_EXTERNAL_GITHUB_REDIRECT_URI=http://localhost:8000/auth/v1/callback
    
    
  5. Start supabase with docker compose using the provided run.sh script in the same folder.

    1
    ./run.sh
    
    • The script will ensure the superagent docker network exists, stops any previously running containers, then runs supabase with docker compose.
    1
    2
    3
    4
    5
    6
    7
    8
    9
     # Check if the network exists
     if ! docker network ls | grep -q superagent_network; then
     # Create the network if it does not exist
     docker network create superagent_network
     fi
    
     ./stop.sh && docker compose up -d
    
     docker logs supabase-db
    
  6. You can access the supabase ui in the browser to confirm the service is up.

    http://localhost:8000 or http://supabase-kong:8000 if you have added the following to your hosts file.

    1
    2
    # hosts file
    127.0.0.1   supabase-kong
    
  7. Login with the values DASHBOARD_USERNAME and DASHBOARD_PASSWORD from libs/.docker/ui/supabase/.env

Supabase Storage

File storage is already configured in the provided supabase docker setup. This is created when you deploy using the script from libs\.docker\ui\supabase\volumes\db\init\data.sql. Though there is one manual step needed to enable superagent to access it:

Required setup to enable storage access

You can access the storage and manage files at the following url

Supabase container logs

1
2
3
4
# Supabase API
docker logs supabase-kong -f
# Supabase Database
docker logs supabase-db -f

Stop supabase

Use the provided stop.sh script to stop running services for supabase

1
2
# libs/.docker/ui/supabase
./stop.sh

Uninstall supabase

Use the provided uninstall.sh script to remove the running services for supabase , this will delete all data stored in the volumes.

1
2
# libs/.docker/ui/supabase
./uninstall.sh

Authentication Examples

Github Authentication Setup

  1. Create a new Github OAuth app in your Github account

  2. Copy the CLIENT_ID and CLIENT_SECRET

  3. Set the following callback URL, for use with docker compose use http://localhost:8000/auth/v1/callback

    1
    2
    <YOUR_SUPABASE_URL>/auth/v1/callback
    
    
  4. Update the environment variables:

    • If using supabase via docker compose - Update the values in the Supabase .env file libs/.docker/ui/supabase/.env
    1
    2
    3
    4
    5
    6
    # libs/.docker/ui/supabase/.env
    GOTRUE_EXTERNAL_GITHUB_ENABLED=true
    GOTRUE_EXTERNAL_GITHUB_CLIENT_ID=<GITHUB - CLIENT_ID>
    GOTRUE_EXTERNAL_GITHUB_SECRET=<GITHUB - CLIENT_SECRET>
    GOTRUE_EXTERNAL_GITHUB_REDIRECT_URI=http://localhost:8000/auth/v1/callback
    
    
    • If using supabase in the cloud: Navigate to your Supabase project you have created for Superagent UI and paste the CLIENT_ID and CLIENT_SECRET
    Screenshot 2023-09-15 at 09 08 52
  5. Finally update the variables in the libs/.docker/.env file

    1
    2
    3
    4
    # libs/.docker/.env
    GITHUB_CLIENT_ID=<GITHUB - CLIENT_ID>
    GITHUB_CLIENT_SECRET=<GITHUB - CLIENT_SECRET>