0.0.4 • Published 2 years ago

google-auth-nestjs v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

google-auth-nestjs

Description

Google login package for NestJs

Instalation

yarn add google-auth-nestjs

Quick Start

  1. Create your Google app and get your credentials (clientId and clientSecret) from Google Cloud panel.

  2. Import GoogleAuthModule on your NestJs module and use forRoot or forRootAsync static methods for initial configuration (configure using your clientId and clientSecret from Google Cloud panel).

import { GoogleAuthModule } from 'google-auth-nestjs';

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

@Injectable()
export class AppService {

  constructor(private readonly service: GoogleAuthService) { }
  
  async getGoogleUser(accessToken: string): Promise<GoogleUserData> {
    return await this.service.getUserData(accessToken);
  }
}
  • To call getUserData method you have to pass the accessToken (sent from front-end login method).