Skip to content

Commit

Permalink
feat/#55/admin 토큰 확인 api 생성 및 refresh 토큰 쿠키 경로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
gwgw123 committed Jan 9, 2025
1 parent 78f0a4f commit 54b20e7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/admin/admin.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Body, Controller, Post, Res, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpCode,
Post,
Res,
UseGuards,
} from '@nestjs/common';
import { LoginAdminDto } from './login-admin.dto';
import { ApiTags } from '@nestjs/swagger';
import { AdminsService } from './admin.service';
import { ApiAdmins } from './admin.swagger';
import { CookieService } from 'src/auth/services/cookie.service';
import { Response } from 'express';
import { AuthGuard } from '@nestjs/passport';
import { User } from 'src/common/decorators/get-user.decorator';

@ApiTags('admins')
@Controller('admins')
Expand All @@ -18,11 +27,19 @@ export class AdminController {
// admin 로그인
@ApiAdmins.LoginAdmin()
@Post('login')
@HttpCode(200)
async loginAdmin(
@Body() loginAdminInfo: LoginAdminDto,
@Res({ passthrough: true }) res: Response,
) {
const accessToken = await this.adminsService.loginAdmin(loginAdminInfo);
await this.cookieService.setAdminAccessTokenCookie(res, accessToken);
}

// accessToken 검증 요청
@ApiAdmins.verifyAdmin()
@Get('verify')
@HttpCode(200)
@UseGuards(AuthGuard('adminAccessToken'))
async verifyToken() {}
}
11 changes: 11 additions & 0 deletions src/admin/admin.swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ export const ApiAdmins = {
}),
);
},
verifyAdmin: () => {
return applyDecorators(
ApiOperation({
summary: 'admin 토큰 인증',
}),
ApiResponse({
status: 200,
description: `admin 토큰이 인증됨`,
}),
);
},
};
2 changes: 1 addition & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class AuthController {
await this.cookieService.deleteCookie(res);
}

// jwt 검증 요청
// accessToken 검증 요청
@Get('verify')
@HttpCode(200)
@UseGuards(AuthGuard('accessToken'))
Expand Down
2 changes: 1 addition & 1 deletion src/auth/services/cookie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class CookieService {
maxAge: Number(
this.configService.get<string>('REFRESH_COOKIE_EXPIRATION_TIME'),
),
path: '/', // refreshToken은 특정 경로로 제한 가능
path: '/auth/new-accessToken', // refreshToken은 특정 경로로 제한
};
res.cookie('refreshToken', refreshToken, refreshTokenCookieOptions);
}
Expand Down

0 comments on commit 54b20e7

Please sign in to comment.