Gathering detailed insights and metrics for @nestjs-mod/supabase
Gathering detailed insights and metrics for @nestjs-mod/supabase
Gathering detailed insights and metrics for @nestjs-mod/supabase
Gathering detailed insights and metrics for @nestjs-mod/supabase
npm install @nestjs-mod/supabase
Typescript
Module System
Min. Node Version
Node Version
NPM Version
two-factor-v1.1.7
Updated on Jul 08, 2025
two-factor-v1.1.6
Updated on Jul 08, 2025
notifications-v1.2.5
Updated on Jul 08, 2025
two-factor-v1.1.5
Updated on Jul 08, 2025
files-v1.2.5
Updated on Jul 08, 2025
supabase-v1.2.3
Updated on Jul 08, 2025
TypeScript (96.75%)
JavaScript (2.51%)
Shell (0.45%)
HTML (0.28%)
Less (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8 Stars
765 Commits
2 Forks
1 Watchers
1 Branches
2 Contributors
Updated on Jul 08, 2025
Latest Version
1.2.3
Package Id
@nestjs-mod/supabase@1.2.3
Unpacked Size
75.75 kB
Size
18.16 kB
File Count
42
NPM Version
10.9.2
Node Version
23.11.1
Published on
Jul 08, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
NestJS JavaScript Client for Supabase (Wrapper for https://www.npmjs.com/package/@supabase/supabase-js)
1npm i --save @supabase/supabase-js@2.49.4 @nestjs-mod/supabase
Link | Category | Description |
---|---|---|
SupabaseModule | core | NestJS JavaScript Client for Supabase (Wrapper for https://www.npmjs.com/package/@supabase/supabase-js) |
NestJS JavaScript Client for Supabase (Wrapper for https://www.npmjs.com/package/@supabase/supabase-js)
An example of using Supabase, you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-supabase/INFRASTRUCTURE.MD.
Test urls
// http://localhost:3000/api/sign-up/a1@email.com/A@@a12345678
// http://localhost:3000/api/sign-in/a1@email.com/A@@a12345678
// http://localhost:3000/api/profile/eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbGxvd2VkX3JvbGVzIjpbInVzZXIiXSwiYXVkIjoiYTJlZDA5ZTEtZmZkMS00YjQ3LWE1MjktZTUzYWU1NDVlZTY1IiwiZXhwIjoxNzQ2NzczODQ3LCJpYXQiOjE3NDY3NzIwNDcsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCIsImxvZ2luX21ldGhvZCI6ImJhc2ljX2F1dGgiLCJub25jZSI6IjdhNzRkOTNhLTNjZDItNDgxMi1hZjY2LTZlMTZiYzZlYjljZCIsInJvbGVzIjpbInVzZXIiXSwic2NvcGUiOlsib3BlbmlkIiwiZW1haWwiLCJwcm9maWxlIl0sInN1YiI6ImEzYjYyZTUwLTQ2Y2MtNDZlNC1iYWRiLTkyYWUwYzhmNGE4ZSIsInRva2VuX3R5cGUiOiJhY2Nlc3NfdG9rZW4ifQ.KUVZ82-wI1V5OhFLF6xUp10b_T4947PMRpnvGlHVTm9A-EBHcl3OzXAxNl5pjbSLdHICVCpiG1zxDOlFoM1kHsTgeG7yBSc5CHFzlAGlPtgYW9wU6exQZ2sidifX3RGcD2nQ0yOaFv0YYURO7AHPP15CIvdsUPZ3016SwAM5JuGjqdriT-5aFHZFMkiHAdETYoGy2oyXQimMdyBxA1ciKKlykhLgEXTvgebqPguKEHj6Vxp3DEpNu3Y0Bm2K9Wog5dgci6rO8ojdsPoni_iyYVJIxdDhdBdax2824uVpgXDDueAKJ6nUQ9v50MlRSj6b5T3gjOETnar8U8bIH0hjZA
AppService
1import { SupabaseService } from '@nestjs-mod/supabase'; 2import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'; 3import { isAxiosError } from 'axios'; 4 5@Injectable() 6export class AppService { 7 private logger = new Logger(AppService.name); 8 9 constructor(private readonly supabaseService: SupabaseService) { } 10 11 getData(): { message: string } { 12 return { message: 'Hello API' }; 13 } 14 15 getTokenFromHeader(headers?: Record<string, string>) { 16 try { 17 return Object.entries(headers || {}).map(([key, value]) => [key.toLowerCase(), value]).find(([key, value]) => key === 'authorization')?.[1]?.split('Bearer ')?.[1] 18 } catch (er) { 19 return '' 20 } 21 } 22 23 async getProfile(headers?: Record<string, string>) { 24 try { 25 const profileResult = await this.supabaseService.getSupabaseClient().auth.getUser(this.getTokenFromHeader(headers)) 26 return profileResult.data 27 } catch (err) { 28 if (isAxiosError(err)) { 29 this.logger.debug(err.response?.data); 30 this.logger.debug(err, err.stack); 31 if (err.response?.data?.message) { 32 throw new HttpException(err.response?.data?.message, HttpStatus.BAD_REQUEST); 33 } 34 } 35 throw new HttpException('Unhandled error', HttpStatus.BAD_REQUEST); 36 } 37 } 38 39 40 async signIn(user: { 41 username?: string; 42 password: string; 43 email: string; 44 }): Promise<string | undefined> { 45 try { 46 const signupUserResult = await this.supabaseService.getSupabaseClient().auth.signInWithPassword({ 47 password: user.password, 48 email: user.email.toLowerCase(), 49 }); 50 return signupUserResult.data?.session?.access_token; 51 } catch (err) { 52 if (isAxiosError(err)) { 53 this.logger.debug(err.response?.data); 54 this.logger.debug(err, err.stack); 55 if (err.response?.data?.message) { 56 throw new HttpException(err.response?.data?.message, HttpStatus.BAD_REQUEST); 57 } 58 } 59 throw new HttpException('Unhandled error', HttpStatus.BAD_REQUEST); 60 } 61 } 62 63 async signUp(user: { 64 username?: string; 65 password: string; 66 email: string; 67 }): Promise<void | null> { 68 try { 69 const signupUserResult = await this.supabaseService.getSupabaseClient().auth.signUp({ 70 password: user.password, 71 email: user.email.toLowerCase() 72 }); 73 74 if (signupUserResult.data.user && signupUserResult.data.user.email) { 75 await this.verifyUser({ 76 externalUserId: signupUserResult.data.user.id!, 77 email: signupUserResult.data.user.email, 78 }); 79 } 80 81 this.logger.debug( 82 `User with email: ${signupUserResult.data.user?.email} successfully created!` 83 ); 84 } catch (err) { 85 if (isAxiosError(err)) { 86 this.logger.debug(err.response?.data); 87 this.logger.debug(err, err.stack); 88 if (err.response?.data?.message) { 89 throw new HttpException(err.response?.data?.message, HttpStatus.BAD_REQUEST); 90 } 91 } 92 throw new HttpException('Failed to create a user', HttpStatus.BAD_REQUEST); 93 } 94 } 95 96 async verifyUser({ 97 externalUserId, 98 email, 99 }: { 100 externalUserId: string; 101 email: string; 102 }) { 103 // for auto verify set in "https://supabase.com/dashboard/project/asuvykozhdurwmnfdhwj/auth/providers?provider=Email - Confirm email" to false 104 return this; 105 } 106} 107
AppController
1import { Controller, Get, Param } from '@nestjs/common'; 2 3import { AllowEmptySupabaseUser } from '@nestjs-mod/supabase'; 4import { AppService } from './app.service'; 5 6@AllowEmptySupabaseUser() 7@Controller() 8export class AppController { 9 constructor(private readonly appService: AppService) { } 10 11 @Get() 12 getData() { 13 return this.appService.getData(); 14 } 15 16 @Get('/sign-up/:email/:password') 17 async signUp(@Param('email') email: string, @Param('password') password: string) { 18 await this.appService.signUp({ 19 email, password 20 }); 21 return { status: 'OK' }; 22 } 23 24 @Get('/sign-in/:email/:password') 25 async signIn(@Param('email') email: string, @Param('password') password: string) { 26 const token = await this.appService.signIn({ 27 email, password 28 }); 29 return { token }; 30 } 31 32 @Get('/profile/:token') 33 async profile(@Param('token') token: string) { 34 return this.appService.getProfile({ Authorization: `Bearer ${token}` }); 35 } 36} 37
AppModule
1import { SupabaseModule } from '@nestjs-mod/supabase'; 2import { createNestModule, NestModuleCategory } from '@nestjs-mod/common'; 3import { AppController } from './app.controller'; 4import { AppService } from './app.service'; 5 6export const { AppModule } = createNestModule({ 7 moduleName: 'AppModule', 8 imports: [SupabaseModule.forFeature()], 9 moduleCategory: NestModuleCategory.feature, 10 controllers: [AppController], 11 providers: [AppService], 12}); 13
main.ts
1process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 2 3import { 4 bootstrapNestApplication, 5 DefaultNestApplicationInitializer, 6 DefaultNestApplicationListener, 7 InfrastructureMarkdownReportGenerator, 8 isInfrastructureMode, 9 PACKAGE_JSON_FILE, 10 ProjectUtils, 11} from '@nestjs-mod/common'; 12import { SupabaseModule } from '@nestjs-mod/supabase'; 13import { join } from 'path'; 14import { AppModule } from './app/app.module'; 15 16const rootFolder = join(__dirname, '..', '..', '..'); 17const appFolder = join(rootFolder, 'apps', 'example-supabase'); 18 19bootstrapNestApplication({ 20 globalConfigurationOptions: { debug: true }, 21 globalEnvironmentsOptions: { debug: true }, 22 modules: { 23 system: [ 24 ProjectUtils.forRoot({ 25 staticConfiguration: { 26 applicationPackageJsonFile: join(__dirname, '..', '..', '..', 'apps/example-supabase', PACKAGE_JSON_FILE), 27 packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE), 28 envFile: join(rootFolder, 'apps', 'example-supabase', '.env'), 29 }, 30 }), 31 DefaultNestApplicationInitializer.forRoot(), 32 DefaultNestApplicationListener.forRoot({ 33 staticConfiguration: { 34 // When running in infrastructure mode, the backend server does not start. 35 mode: isInfrastructureMode() ? 'silent' : 'listen', 36 }, 37 }), 38 ], 39 feature: [ 40 SupabaseModule.forRootAsync({ 41 staticEnvironments: { 42 // Supabase URL (https://supabase.com/dashboard/project/XXX/settings/api - API Settings - Project URL - URL) 43 url: 'https://asuvykozhdurwmnfdhwj.supabase.co', 44 // Supabase key (https://supabase.com/dashboard/project/XXX/settings/api - API Settings - Project API Keys - anon public) 45 key: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFzdXZ5a296aGR1cndtbmZkaHdqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDczMjQ1MTksImV4cCI6MjA2MjkwMDUxOX0.Xe0eHD_cNhiMGaKfwP53-_0XhZ09oaC5OKQ4gsPbwV0' 46 }, 47 }), 48 AppModule.forRoot() 49 ], 50 infrastructure: [ 51 InfrastructureMarkdownReportGenerator.forRoot({ 52 staticConfiguration: { 53 markdownFile: join(appFolder, 'INFRASTRUCTURE.MD'), 54 skipEmptySettings: true, 55 style: 'pretty', 56 }, 57 }), 58 ], 59 }, 60}); 61
When launched in the infrastructure documentation generation mode, the module creates an .env
file with a list of all required variables, as well as an example example.env
, where you can enter example variable values.
SupabaseService
Key | Description | Constraints | Default | Value |
---|---|---|---|---|
extraHeaders | Extra headers | optional | - | - |
checkAccessValidator | External function for validate permissions | optional | defaultSupabaseCheckAccessValidator | - |
externalUserIdHeaderName | A header for searching for an external user ID, if you have logged in previously and do not need to log in again in the authorization service, can be used during testing | optional | x-external-user-id | - |
externalAppIdHeaderName | Header for searching for external application identifiers, if you have logged in previously and do not need to log in again in the authorization service, these identifiers must be private and can be used for testing | optional | x-external-app-id | - |
getSupabaseUserFromExternalUserId | Function for resolve supabase user by externalUserId | optional | defaultSupabaseGetSupabaseUserFromExternalUserId | - |
clientOptions | Supabase client options | optional | - | - |
Key | Description | Sources | Constraints | Default | Value |
---|---|---|---|---|---|
url | Supabase URL (https://supabase.com/dashboard/project/XXX/settings/api - API Settings - Project URL - URL) | obj['url'] , process.env['SUPABASE_URL'] | isNotEmpty (url should not be empty) | - | - |
key | Supabase key (https://supabase.com/dashboard/project/XXX/settings/api - API Settings - Project API Keys - anon public) | obj['key'] , process.env['SUPABASE_KEY'] | isNotEmpty (key should not be empty) | - | - |
allowedExternalAppIds | Allowed identifiers of external applications, if you have logged in previously and do not need to log in again in the authorization service, these identifiers must be private and can be used for testing | obj['allowedExternalAppIds'] , process.env['SUPABASE_ALLOWED_EXTERNAL_APP_IDS'] | optional | - | - |
useGuards | Use guards | obj['useGuards'] , process.env['SUPABASE_USE_GUARDS'] | optional | true | true |
useFilters | Use filters | obj['useFilters'] , process.env['SUPABASE_USE_FILTERS'] | optional | true | true |
Key | Description | Constraints | Default | Value |
---|
MIT
No vulnerabilities found.
No security vulnerabilities found.