fixed logical error
This commit is contained in:
@@ -23,41 +23,13 @@ export class PersonaController {
|
|||||||
@Get('google/callback')
|
@Get('google/callback')
|
||||||
@UseGuards(GoogleAuthGuard)
|
@UseGuards(GoogleAuthGuard)
|
||||||
async googleCallback(@Req() req, @Res() res: Response) {
|
async googleCallback(@Req() req, @Res() res: Response) {
|
||||||
const googleUser = req.user;
|
const persona = req.user; // Ya viene desde GoogleStrategy.validate()
|
||||||
|
|
||||||
if (!googleUser) {
|
|
||||||
return res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`);
|
|
||||||
}
|
|
||||||
let persona = await this.personaService.findByEmail(googleUser.email);
|
|
||||||
|
|
||||||
if (!persona) {
|
if (!persona) {
|
||||||
const apellidos = (googleUser.apellido || '').trim().split(' ');
|
return res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`);
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Genera JWT con los datos de la persona
|
// Generar JWT con los datos de la persona
|
||||||
const jwt = await this.personaService.generateJwt(persona);
|
const jwt = await this.personaService.generateJwt(persona);
|
||||||
|
|
||||||
return res.redirect(
|
return res.redirect(
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ export class PersonaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByEmail(email: string): Promise<Persona | null> {
|
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> {
|
async create(data: Partial<Persona>): Promise<Persona> {
|
||||||
|
|||||||
Reference in New Issue
Block a user