1.0.0 • Published 1 year ago

@nestixis/nestjs-supabase v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

nestjs-supabase

Installation

To install the package, run:

npm i @nestixis/nestjs-supabase

Registration

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 { ConfigModule, ConfigService } from "@nestjs/config";

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],
});

Usage

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;
  }
}
1.0.0

1 year ago