0.0.4 • Published 11 months ago

facebook-auth-nestjs v0.0.4

Weekly downloads
13
License
ISC
Repository
github
Last release
11 months ago

facebook-auth-nestjs

Description

Facebook login package for NestJs

Instalation

npm i facebook-auth-nestjs

Quick Start

  1. Create your Facebook's app and get your credentials (clientId and clientSecret) from Facebook's panel.

  2. Import FacebookAuthModule on your NestJs module and use forRoot or forRootAsync static methods for initial configuration (configure using your clientId and clientSecret from Facebook's panel).

import { FacebookAuthModule } from 'facebook-auth-nestjs';

@Module({
  imports: [
    FacebookAuthModule.forRoot({
      clientId: your-facebook-clientid,
      clientSecret: your-facebook-client-secret,
    }),
  ],
})
export class AppModule { }
  1. Import FacebookAuthService on your service or controller and use getUser method to get user's information from Facebook.
import { FacebookAuthService } from 'facebook-auth-nestjs';

@Injectable()
export class AppService {

  constructor(private readonly service: FacebookAuthService) { }
  
  async getFacebookUser(accessToken: string): Promise<{ id: string, name: string }> {
    return await this.service.getUser(accessToken, 'id', 'name');
  }
}
  • To call getUser method you have to pass the accessToken (sent from front-end login method) and pass the user's fields you want (id, first_name, etc..).
  • If you want a field in additional to 'id', 'name', 'first_name' or 'last_name', you must set the corresponding scope permission on the front-end login method. Ex: to get birthday field on getUser method, you must add the 'user_birthday' scope permission on your front-end login method.

Facebook References