facebook-auth-nestjs
v0.0.4
Published
facebook-auth-nestjs
Downloads
1,493
Readme
facebook-auth-nestjs
Description
Facebook login package for NestJs
Instalation
npm i facebook-auth-nestjs
Quick Start
Create your Facebook's app and get your credentials (clientId and clientSecret) from Facebook's panel.
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 { }
- 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.