Se agregó el inicio de sesion de google

This commit is contained in:
2025-09-02 13:58:37 -06:00
parent 8ad6db15dc
commit d8d2154cbe
15 changed files with 873 additions and 298 deletions
+73 -1
View File
@@ -1,10 +1,13 @@
import { AuthDocumentation } from './auth.documentation';
import { Controller, Post, Body, UseGuards, Request, Get } from '@nestjs/common';
import { Controller, Post, Body, UseGuards, Request, Get, Req, Res } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginDto } from './dto/login.dto';
import { AuthGuard } from '@nestjs/passport';
import { RegisterDto } from './dto/register.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { SetPasswordDto } from './dto/createPassword.dto';
import { Response } from 'express';
import { WhiteDto } from './dto/whiteList.dto';
@Controller()
export class AuthController {
@@ -34,6 +37,8 @@ export class AuthController {
};
}
@@ -43,6 +48,73 @@ export class AuthController {
return this.authService.register(dto);
}
@Post('white-list')
@AuthDocumentation.white()
async newRegister(@Body() dto:WhiteDto){
return this.authService.white(dto)
}
//Inicio de sesión con GOOGLE
@Get('google')
@UseGuards(AuthGuard('google'))
async googleLogin() {
return { msg: 'Redirigiendo a Google' };
}
// Callback de Google
// @Get('google/callback')
// @UseGuards(AuthGuard('google'))
// async googleCallback(@Req() req) {
// const user = req.user;
// if (user.needsPassword) {
// return {
// status: 'NEEDS_PASSWORD',
// email: user.correo,
// message: 'El usuario debe crear una contraseña antes de continuar',
// };
// }
// return this.authService.login(user); // genera JWT
// }
// auth.controller.ts
@Get('google/callback')
@UseGuards(AuthGuard('google'))
async googleCallback(@Req() req, @Res() res: Response) {
const user = req.user;
if (user.needsPassword) {
return res.redirect(
`${process.env.FRONTEND_URL}/password?email=${user.correo}`,
);
}
const jwt = await this.authService.login(user);
return res.redirect(
`${process.env.FRONTEND_URL}/oauth-callback?token=${jwt.access_token}`,
);
}
//Inicio de sesión con GOOGLE
//Set-contraseña
// auth.controller.ts
@Post('set-password')
async setPassword(@Body() dto: SetPasswordDto) {
return this.authService.setPassword(dto);
}
}