[UPD] add google auth route
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// users/users.controller.ts
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
@@ -7,7 +9,11 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Delete,
|
Delete,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
|
Req,
|
||||||
|
Res,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
@@ -52,4 +58,24 @@ export class UsersController {
|
|||||||
remove(@Param('id') id: string): Promise<User> {
|
remove(@Param('id') id: string): Promise<User> {
|
||||||
return this.usersService.deleteUser({ id: +id });
|
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}`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user