Se agregó el inicio de sesion de google
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// google.strategy.ts
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly config: ConfigService,
|
||||
) {
|
||||
super({
|
||||
clientID: config.get<string>('GOOGLE_CLIENT_ID'),
|
||||
clientSecret: config.get<string>('GOOGLE_CLIENT_SECRET'),
|
||||
callbackURL: config.get<string>('GOOGLE_CALLBACK_URL'),
|
||||
scope: ['email', 'profile'],
|
||||
});
|
||||
}
|
||||
|
||||
async validate(
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: any,
|
||||
done: VerifyCallback,
|
||||
): Promise<any> {
|
||||
const { emails } = profile;
|
||||
const email = emails[0].value;
|
||||
|
||||
const user = await this.authService.validateGoogleUser(email);
|
||||
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('Usuario no registrado en el sistema');
|
||||
}
|
||||
|
||||
done(null, user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user