Skip to content

Instantly share code, notes, and snippets.

@iMichaelOwolabi
Created April 29, 2020 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iMichaelOwolabi/aca1cb4ae00512c82e76c5dd9d4a1ceb to your computer and use it in GitHub Desktop.
Save iMichaelOwolabi/aca1cb4ae00512c82e76c5dd9d4a1ceb to your computer and use it in GitHub Desktop.
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
import { config } from 'dotenv';
import { Injectable } from '@nestjs/common';
config();
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
constructor() {
super({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_SECRET,
callbackURL: 'http://localhost:3000/google/redirect',
scope: ['email', 'profile'],
});
}
async validate (accessToken: string, refreshToken: string, profile: any, done: VerifyCallback): Promise<any> {
const { name, emails, photos } = profile
const user = {
email: emails[0].value,
firstName: name.givenName,
lastName: name.familyName,
picture: photos[0].value,
accessToken
}
done(null, user);
}
}
@clorichel
Copy link

Need to replace done(null, user); with done(undefined, user); or 💥

error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | Error | undefined'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment