20 lines
562 B
TypeScript
20 lines
562 B
TypeScript
|
|
// google-auth.guard.ts
|
||
|
|
import { Injectable } from '@nestjs/common';
|
||
|
|
import { AuthGuard } from '@nestjs/passport';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class GoogleAuthGuard extends AuthGuard('google') {
|
||
|
|
handleRequest(err: any, user: any, info: any, context: any) {
|
||
|
|
const req = context.switchToHttp().getRequest();
|
||
|
|
const res = context.switchToHttp().getResponse();
|
||
|
|
|
||
|
|
if (err || !user) {
|
||
|
|
// 👇 siempre redirigir al front en caso de error
|
||
|
|
res.redirect(`${process.env.FRONTEND_URL}?error=oauth_failed`);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return user;
|
||
|
|
}
|
||
|
|
}
|