To install the package, run:
npm i @nestixis/nestjs-supabase
To register the module in your application, you can use the SupabaseSdkModule.registerAsync
method with a factory pattern:
import { SupabaseSdkModule } from '@nestixis/nestjs-supabase';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [
SupabaseSdkModule.registerAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
auth: {
url: configService.get<string>('SUPABASE_AUTH_URL'),
key: configService.get<string>('SUPABASE_SERVICE_ROLE_KEY'),
},
}),
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
To use the Supabase client in your service, inject it using the SUPABASE_SDK_CLIENT
token:
import { SupabaseClient } from '@supabase/supabase-js';
import { Inject } from '@nestjs/common';
import { SUPABASE_SDK_CLIENT } from '@nestixis/nestjs-supabase';
@Injectable()
export class YourService {
constructor(
@Inject(SUPABASE_SDK_CLIENT) private readonly supabaseClient: SupabaseClient
) {}
async yourMethod() {
const { data, error } = await this.supabaseClient
.from('your_table')
.select('*');
if (error) {
throw error;
}
return data;
}
}