Se agregó el inicio de sesion de google

This commit is contained in:
2025-09-02 13:58:37 -06:00
parent 8ad6db15dc
commit d8d2154cbe
15 changed files with 873 additions and 298 deletions
+39
View File
@@ -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);
}
}