From 2e40e4366e050d40726b746ded1a09b1f805ac20 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Fri, 17 Oct 2025 12:52:27 -0600 Subject: [PATCH] fixed logical error --- src/persona/persona.controller.ts | 34 +++---------------------------- src/persona/persona.service.ts | 6 +++++- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/persona/persona.controller.ts b/src/persona/persona.controller.ts index ee6c666..a06910a 100644 --- a/src/persona/persona.controller.ts +++ b/src/persona/persona.controller.ts @@ -23,41 +23,13 @@ export class PersonaController { @Get('google/callback') @UseGuards(GoogleAuthGuard) async googleCallback(@Req() req, @Res() res: Response) { - const googleUser = req.user; - - if (!googleUser) { - return res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`); - } - let persona = await this.personaService.findByEmail(googleUser.email); + const persona = req.user; // Ya viene desde GoogleStrategy.validate() if (!persona) { - const apellidos = (googleUser.apellido || '').trim().split(' '); - const apellidoP = apellidos[0] || ''; - const apellidoM = apellidos.slice(1).join(' ') || ''; - - const numeroIdentificar = googleUser.email.split('@')[0]; - - persona = await this.personaService.create({ - nombre: googleUser.nombre || '', - apellidoP, - apellidoM, - password: '', // vacĂ­o porque es login OAuth - passwordTem: '', - fechaPasswordTem: new Date(), - correo: googleUser.email, - carreraAds: '', - cantidadCuenta: 0, - usuario: '', - numeroIdentificar, - tipoUsuario: '', - correoEnviado: false, - fechaRegistro: new Date(), - cambioPasswordReq: true, - primerLogin: false, - }); + return res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`); } - // Genera JWT con los datos de la persona + // Generar JWT con los datos de la persona const jwt = await this.personaService.generateJwt(persona); return res.redirect( diff --git a/src/persona/persona.service.ts b/src/persona/persona.service.ts index 75d1fa1..aefd6c1 100644 --- a/src/persona/persona.service.ts +++ b/src/persona/persona.service.ts @@ -19,7 +19,11 @@ export class PersonaService { } async findByEmail(email: string): Promise { - return this.personaRepository.findOne({ where: { correo: email } }); + const user = await this.personaRepository.findOne({ + where: { correo: email }, + }); + console.log('service', user); + return user; } async create(data: Partial): Promise {