Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.24 KB

README.md

File metadata and controls

44 lines (32 loc) · 1.24 KB

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-google-clientid',
      clientSecret: 'your-google-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).