diff --git a/back/src/users/users.controller.ts b/back/src/users/users.controller.ts index ca5b5f2..8c8ac5e 100644 --- a/back/src/users/users.controller.ts +++ b/back/src/users/users.controller.ts @@ -1,3 +1,5 @@ +// users/users.controller.ts + import { Controller, Get, @@ -7,7 +9,11 @@ import { Param, Delete, NotFoundException, + Req, + Res, + UseGuards, } from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; import { UsersService } from './users.service'; import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; @@ -52,4 +58,24 @@ export class UsersController { remove(@Param('id') id: string): Promise { return this.usersService.deleteUser({ id: +id }); } + + // Google OAuth - Call this endpoint to start the OAuth flow + @Get('google') + @UseGuards(AuthGuard('google')) + async googleAuth() {} + + // Google OAuth - Callback endpoint + @Get('google/callback') + @UseGuards(AuthGuard('google')) + async googleAuthCallback(@Req() req, @Res() res) { + try { + const user = req.user; + // Redirect to frontend with auth information + res.redirect(''); // TODO: Add frontend url format example : http://localhost:3000/success?user=${JSON.stringify(user)}` + } catch (err) { + // Redirect to frontend with error information + console.error(err); + res.redirect(''); // TODO: Add frontend url format example : http://localhost:3000/error?error=${err}` + } + } }