Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self host Supabase service #2743

Merged

Conversation

DukeManh
Copy link
Contributor

@DukeManh DukeManh commented Jan 26, 2022

Issue This PR Addresses

Part of #2555. This adds a Supbase self-hosted instance to Telescope.

Note: This pr also fixes the SignUpPage crash bug mentioned in #2676. @nguyenhung15913 , you can take a look at AuthProvider here as a starting point of your PR.

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Testing Supabase

  1. Go to the Supabase service
  cd src/api/supabase
  1. Copy the env vars
  cp .env.example .env
  1. Start
  docker-compose up
  1. Go to localhost:8910 to visit the Dashboard

Testing Supabase API in the auth service

  1. Do all the steps above
  2. Uncomment Sign Up link in BannerButtons in
    {/* <Link href="/signup" passHref>
    <Button
    style={{
    fontSize: '1.3rem',
    }}
    variant="outlined"
    >
    Sign up
    </Button>
    </Link> */}
  3. In /src/api/auth/src/middleware.js, replace line 92 to 110
    const id = getUserId(req);
    const response = await fetch(`${USERS_URL}/${id}`, {
    method: 'POST',
    headers: {
    // re-use the user's authorization header and token
    Authorization: req.get('Authorization'),
    'Content-Type': 'application/json',
    },
    body: JSON.stringify(req.body),
    });
    if (response.status !== 201) {
    logger.warn(
    { status: response.status, id, data: req.body },
    'unable to create user with Users service'
    );
    next(createError(response.status, 'unable to create user'));
    return;
    }

with

      const supabase = require('./supabase');
      ...
      const { email } = req.user;
      const { user, error } = await supabase.auth.api.createUser({
        email,
        password: 'hello',
        data: req.body,
      });

      if (error) {
        logger.warn({ status: error.status, email, data: req.body }, error.message);
        next(createError(error.status, 'unable to create user'));
        return;
      }
  1. Go to localhost:8000 to Sign Up using an example account:
    • username: user1
    • password: user1pass
  2. Finish the user registration flow
  3. Vist the Supabase dashboard again at localhost:8910 and check the user list. A new user is created!

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

@DukeManh DukeManh requested review from humphd and HyperTHD January 26, 2022 01:18
@DukeManh DukeManh requested a review from manekenpix January 26, 2022 01:18
@DukeManh DukeManh self-assigned this Jan 26, 2022
@manekenpix manekenpix changed the title Self host Supbase service Self host Supabase service Jan 26, 2022
@DukeManh DukeManh force-pushed the dukemanh/investigate-supabase-2555 branch from 6a656d7 to 4913215 Compare January 26, 2022 01:33
@gitpod-io
Copy link

gitpod-io bot commented Jan 26, 2022

src/api/auth/package.json Outdated Show resolved Hide resolved
src/api/supabase/docker-compose.yml Outdated Show resolved Hide resolved
src/api/auth/src/supabase.js Outdated Show resolved Hide resolved
src/api/auth/src/supabase.js Outdated Show resolved Hide resolved
@humphd
Copy link
Contributor

humphd commented Jan 27, 2022

Filed #2748 to fix the auth build

@DukeManh
Copy link
Contributor Author

Why do I have pnpm-lock.yaml after installing @supabase/supabase-js? I installed with pnpm add inside 'sr/api/auth'

@humphd
Copy link
Contributor

humphd commented Jan 27, 2022

Created #2752 to fix the naming of auth containers.

@DukeManh DukeManh force-pushed the dukemanh/investigate-supabase-2555 branch from 45958fd to e00124f Compare January 27, 2022 16:41
@DukeManh DukeManh marked this pull request as ready for review January 27, 2022 16:42
@humphd
Copy link
Contributor

humphd commented Jan 27, 2022

Can you rebase to pick up the changes from #2752?

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move supabase out of src/api and put it in docker/supabase, since that's what it is (i.e., a bunch of docker and config files).

Next, let's modify https://github.com/Seneca-CDOT/telescope/blob/master/config/env.development#L13 so that it adds a third docker-compose file to our list:

COMPOSE_FILE=docker/docker-compose.yml;docker/development.yml;docker/supabase/docker-compose.yml

Next, let's move everything in supabase/env.example to config/env.development under a new Supabase section. That is, let's merge the Supabase variables with ours.

Next, lets update all of the volumes relative paths in the Supabase docker-compose files (there are two), so that it uses ./supabase/volumes vs. ./volumes. We'll have to confirm that I have this right, but basically, we need to use a relative path for the new location, which is the merged path (i.e., the first docker-compose.yml we have in docker).

We won't add any of this to staging or production yet, only for development and gitpod. That way we can iterate on it and secure things before we ship it to staging.

@DukeManh
Copy link
Contributor Author

@humphd works for me on Gitpod.

@DukeManh DukeManh requested a review from humphd January 28, 2022 18:18
config/env.development Outdated Show resolved Hide resolved
config/env.development Show resolved Hide resolved
config/env.development Outdated Show resolved Hide resolved
config/env.production Outdated Show resolved Hide resolved
config/env.staging Outdated Show resolved Hide resolved
docker/supabase/.env.example Outdated Show resolved Hide resolved
config/env.development Outdated Show resolved Hide resolved
config/env.development Outdated Show resolved Hide resolved
config/env.development Show resolved Hide resolved
config/env.development Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/supabase/docker-compose.yml Show resolved Hide resolved
docker/supabase/docker-compose.yml Show resolved Hide resolved
docker/supabase/docker-compose.yml Show resolved Hide resolved
docker/supabase/docker-compose.yml Outdated Show resolved Hide resolved
@DukeManh
Copy link
Contributor Author

@manekenpix, could you also take a look, please?

config/env.development Outdated Show resolved Hide resolved
config/env.development Show resolved Hide resolved
config/env.development Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/supabase/docker-compose.yml Show resolved Hide resolved
humphd
humphd previously approved these changes Feb 1, 2022
docker/supabase/docker-compose.yml Show resolved Hide resolved
docker/supabase/docker-compose.yml Show resolved Hide resolved
manekenpix
manekenpix previously approved these changes Feb 1, 2022
Copy link
Member

@manekenpix manekenpix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping an eye on the open ports

@DukeManh DukeManh merged commit 1d3a59e into Seneca-CDOT:master Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants