Created
April 29, 2020 18:08
-
-
Save iMichaelOwolabi/aca1cb4ae00512c82e76c5dd9d4a1ceb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to replace
done(null, user);
withdone(undefined, user);
or 💥