danedyy / nestjs-supabase-setup

Home Page:https://blog.andriishupta.dev/setup-supabase-with-nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

https://blog.andriishupta.dev/setup-supabase-with-nestjs


Languages

Language:TypeScript 89.5%Language:JavaScript 10.5%