againd modified googleauth

This commit is contained in:
2025-10-29 17:51:35 -06:00
parent c34ea0c1bb
commit 76a86ae3b0
@@ -1,33 +1,21 @@
import { Injectable, ExecutionContext } from '@nestjs/common';
import {
Injectable,
ExecutionContext,
UnauthorizedException,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class GoogleAuthGuard extends AuthGuard('google') {
handleRequest(err, user, info, context: ExecutionContext) {
const req = context.switchToHttp().getRequest();
const res = context.switchToHttp().getResponse();
// Solo redirigir si hay info Y no hay user
if (info && !user) {
if (err || !user) {
return res.redirect(
`${process.env.FRONTEND_URL}/oauth-callback?error=${info.message || info}`,
);
}
// Si hay error de validación en validate()
if (err) {
return res.redirect(
`${process.env.FRONTEND_URL}/oauth-callback?error=${err.message || 'oauth_failed'}`,
);
}
// Si no hay usuario (pero sin info), redirigimos con error
if (!user) {
return res.redirect(
`${process.env.FRONTEND_URL}/oauth-callback?error=oauth_failed`,
);
}
return user; // login exitoso
return user;
}
}