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();
|
2026-01-09 12:58:08 -06:00
|
|
|
|
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`);
|
2026-01-09 12:58:08 -06:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|