facebook-auth-nestjs
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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

  1. Facebook's front-end login: https://developers.facebook.com/docs/reference/javascript/FB.login/v8.0
  2. Facebook's scope permissions: https://developers.facebook.com/docs/permissions/reference
  3. Facebook's user fields https://developers.facebook.com/docs/graph-api/reference/user

Readme

Keywords

Package Sidebar

Install

npm i facebook-auth-nestjs

Weekly Downloads

191

Version

0.0.4

License

ISC

Unpacked Size

31.3 kB

Total Files

41

Last publish

Collaborators

  • devmontagnini