mirror change from https://github.com/binhkid2/FullStack-Blog-Nestjs-Nextjs-Postgres
This commit is contained in:
32
backend/src/auth/strategies/google.strategy.ts
Normal file
32
backend/src/auth/strategies/google.strategy.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
constructor(configService: ConfigService) {
|
||||
super({
|
||||
clientID: configService.get<string>('GOOGLE_CLIENT_ID') || 'dummy',
|
||||
clientSecret: configService.get<string>('GOOGLE_CLIENT_SECRET') || 'dummy',
|
||||
callbackURL: configService.get<string>('GOOGLE_CALLBACK_URL'),
|
||||
scope: ['email', 'profile'],
|
||||
});
|
||||
}
|
||||
|
||||
async validate(
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: any,
|
||||
done: VerifyCallback,
|
||||
): Promise<any> {
|
||||
const { id, displayName, emails } = profile;
|
||||
const user = {
|
||||
providerId: id,
|
||||
provider: 'google',
|
||||
email: emails?.[0]?.value,
|
||||
name: displayName,
|
||||
};
|
||||
done(null, user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user