Installations
npm install nestjs-supabase-js
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.18.1
NPM Version
10.8.2
Score
64.3
Supply Chain
97.8
Quality
83.5
Maintenance
100
Vulnerability
99.3
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (85.09%)
JavaScript (14.91%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
adrianmjim
Download Statistics
Total Downloads
3,770
Last Day
8
Last Week
134
Last Month
671
Last Year
3,770
GitHub Statistics
MIT License
10 Stars
122 Commits
3 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Feb 12, 2025
Bundle Size
6.46 kB
Minified
1.55 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.1
Package Id
nestjs-supabase-js@1.1.1
Unpacked Size
65.91 kB
Size
16.22 kB
File Count
100
NPM Version
10.8.2
Node Version
20.18.1
Published on
Jan 21, 2025
Total Downloads
Cumulative downloads
Total Downloads
3,770
Last Day
-69.2%
8
Compared to previous day
Last Week
-14.6%
134
Compared to previous week
Last Month
109.7%
671
Compared to previous month
Last Year
0%
3,770
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
2
Description
The Supabase module for NestJS.
Installation
Install the dependencies via npm
, pnpm
or yarn
:
npm:
1$ npm i -s @nestjs/common @supabase/supabase-js nestjs-supabase-js
pnpm:
1$ pnpm add @nestjs/common @supabase/supabase-js nestjs-supabase-js
yarn:
1$ yarn add @nestjs/common @supabase/supabase-js nestjs-supabase-js
Configuration
First, import the module into your NestJS application and configure it using the configuration key provided by Supabase.
1import { Module } from '@nestjs/common'; 2import { SupabaseModule } from 'nestjs-supabase-js'; 3 4@Module({ 5 imports: [ 6 SupabaseModule.forRoot({ 7 supabaseKey: 'YOUR_SUPABASE_KEY', 8 supabaseUrl: 'YOUR_SUPABASE_URL', 9 }), 10 ], 11}) 12export class AppModule {}
Or, You can configure it asynchronously as follows:
1import { Module } from '@nestjs/common'; 2import { SupabaseModule } from 'nestjs-supabase-js'; 3 4@Module({ 5 imports: [ 6 SupabaseModule.forRootAsync({ 7 imports: [], 8 inject: [], 9 useFactory: () => ({ 10 supabaseKey: 'YOUR_SUPABASE_KEY', 11 supabaseUrl: 'YOUR_SUPABASE_URL', 12 }), 13 }), 14 ], 15}) 16export class AppModule {}
Multiple connections
In certain situations, we will need to connect to different Supabase projects, with this module this is possible:
1import { Module } from '@nestjs/common'; 2import { SupabaseModule } from 'nestjs-supabase-js'; 3 4@Module({ 5 imports: [ 6 SupabaseModule.forRoot([ 7 { 8 name: 'connection1', 9 supabaseConfig: { 10 supabaseKey: 'YOUR_SUPABASE_KEY', 11 supabaseUrl: 'YOUR_SUPABASE_URL', 12 }, 13 }, 14 { 15 name: 'connection2', 16 supabaseConfig: { 17 supabaseKey: 'YOUR_SUPABASE_KEY', 18 supabaseUrl: 'YOUR_SUPABASE_URL', 19 }, 20 }, 21 ]), 22 ], 23}) 24export class AppModule {}
Or asynchronously:
1import { Module } from '@nestjs/common'; 2import { SupabaseModule } from 'nestjs-supabase-js'; 3 4@Module({ 5 imports: [ 6 SupabaseModule.forRootAsync({ 7 imports: [], 8 inject: [], 9 useFactory: () => ([ 10 { 11 name: 'connection1', 12 supabaseConfig: { 13 supabaseKey: 'YOUR_SUPABASE_KEY', 14 supabaseUrl: 'YOUR_SUPABASE_URL', 15 }, 16 }, 17 { 18 name: 'connection2', 19 supabaseConfig: { 20 supabaseKey: 'YOUR_SUPABASE_KEY', 21 supabaseUrl: 'YOUR_SUPABASE_URL', 22 }, 23 }, 24 ]), 25 }), 26 ], 27}) 28export class AppModule {}
Usage
First, inject the client into the module where you want to use it:
1import { Module } from '@nestjs/common'; 2import { SupabaseModule } from 'nestjs-supabase-js'; 3 4@Module({ 5 imports: [ 6 SupabaseModule.injectClient(), 7 ], 8}) 9export class CatModule {}
Or, for a specific connection:
1import { Module } from '@nestjs/common'; 2import { SupabaseModule } from 'nestjs-supabase-js'; 3 4@Module({ 5 imports: [ 6 SupabaseModule.injectClient('connection1', 'connection2'), 7 ], 8}) 9export class CatModule {}
Now you can use the Supabase client in any provider of your module:
1import { SupabaseClient } from '@supabase/supabase-js'; 2 3export class CatService { 4 constructor(private readonly supabaseClient: SupabaseClient) {} 5 6 public doSomething(): void { 7 8 } 9}
Or, for a specific connection:
1import { SupabaseClient } from '@supabase/supabase-js'; 2import { InjectSupabaseClient } from 'nestjs-supabase-js'; 3 4export class CatService { 5 constructor( 6 @InjectSupabaseClient('connection1') private readonly supabaseClient1: SupabaseClient, 7 @InjectSupabaseClient('connection2') private readonly supabaseClient2: SupabaseClient, 8 ) {} 9 10 public doSomething(): void { 11 12 } 13}
It's also possible to use the InjectSupabaseClient decorator to inject the Supabase client when you don't want to explicitly type it with the client:
1import { SupabaseClient } from '@supabase/supabase-js'; 2import { InjectSupabaseClient } from 'nestjs-supabase-js'; 3 4export class CatService { 5 constructor( 6 @InjectSupabaseClient() private readonly supabaseClient: unknown, 7 ) {} 8 9 public doSomething(): void { 10 11 } 12}
Authentication
This library provides a base guard to authenticate requests using the Supabase auth client.
Usage
To create your own guard that authenticates against Supabase, you just need to create a new guard that extends BaseSupabaseAuthGuard
and implements the method extractTokenFromRequest
. This implementation should define how to extract the token from the request, which might be in the headers, cookies, or query parameters.
1import { Injectable, ExecutionContext } from '@nestjs/common'; 2import { SupabaseClient } from '@supabase/supabase-js'; 3import { BaseSupabaseAuthGuard } from 'nestjs-supabase-js'; 4 5@Injectable() 6export class MyAuthGuard extends BaseSupabaseAuthGuard { 7 public constructor(supabaseClient: SupabaseClient) { 8 super(supabaseClient); 9 } 10 11 protected extractTokenFromRequest(request: Request): string | undefined { 12 return request.headers.authorization; 13 } 14}
Then, you can bind the guard as described in the NestJS documentation.
🤝 Contributing 
Contributions, issues and feature requests are welcome.
Authors
👤 Adrián Martínez Jiménez
- Github: @adrianmjim
See also the list of contributors who participated in this project.
Show Your Support
Please ⭐️ this repository if this project helped you!
📝 License
Copyright © 2024 Adrián Martínez Jiménez.
This project is licensed under the MIT License - see the LICENSE file for details.

No vulnerabilities found.

No security vulnerabilities found.