Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

andriishupta/nestjs-supabase-setup

Repository files navigation

nestjs-supabase-setup

This is an example for Supabase v1. The API has changed in later versions, but the most important idea here - use NestJS's Services with the correct scope to have a separate SupabaseInstance for different requests https://docs.nestjs.com/fundamentals/injection-scopes

Description

This is an example of how to setup and use Supabase with Nest.js: Auth and Client. Follow the article for more info.

Using in your app:

  • copy supabase folder
  • import SupabaseModule where you need
  • add APP_GUARD for global Auth guarding or use UseGuard() per route
  • use supabase.getClient() that will create you a "per request client" with Scope.REQUEST option - this is essential, such as we cannot setAuth() like on the client-side once

Installation

$ npm install

Running the app

  • add valid .env file from your Supabase
  • get user's access_token
  • update code in AppService that matches your business logic / table name / etc.
  • use access_token as your Bearer Authorization
  • start application*
  • make GET / request
$ npm run start