Files
cargaMasiva_api/src/auth/google-auth.guard.ts
T

18 lines
488 B
TypeScript
Raw Normal View History

2025-09-12 14:18:08 -06:00
import { Injectable, UnauthorizedException } from '@nestjs/common';
2025-09-12 12:38:15 -06:00
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class GoogleAuthGuard extends AuthGuard('google') {
2025-09-12 14:18:08 -06:00
handleRequest(err, user, info, context) {
2025-09-12 12:38:15 -06:00
const res = context.switchToHttp().getResponse();
2025-09-12 14:18:08 -06:00
if (err) {
// redirige directamente y corta la ejecución
2025-09-12 12:38:15 -06:00
res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`);
2025-09-12 12:38:15 -06:00
}
2025-09-12 14:18:08 -06:00
return user; // si existe, sigue normalmente
2025-09-12 12:38:15 -06:00
}
}