fixed logical error

This commit is contained in:
2025-10-17 12:52:27 -06:00
parent 10d71b19d1
commit 2e40e4366e
2 changed files with 8 additions and 32 deletions
+3 -31
View File
@@ -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(
+5 -1
View File
@@ -19,7 +19,11 @@ export class PersonaService {
}
async findByEmail(email: string): Promise<Persona | null> {
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<Persona>): Promise<Persona> {