Skip to content

Commit

Permalink
setting/#65/pull develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gwgw123 committed Jan 9, 2025
2 parents 8184219 + 42058d4 commit 202b0ff
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI/CD Docker
# 트리거를 수행할 브랜치를 지정합니다.
on:
push:
branches: [main, develop, feat/#55/admin-login-api-feat]
branches: [main, develop]

# 환경설정
env:
Expand Down
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() {}
}
2 changes: 0 additions & 2 deletions src/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class AdminsService {

const accessToken = await this.tokenService.createAdminAccessToken('admin');

console.log(accessToken);

return accessToken;
}

Expand Down
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
2 changes: 0 additions & 2 deletions src/parts/parts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { PartsRepository } from './parts.repository';
import { QuizzesModule } from 'src/quizzes/quizzes.module';
import { SectionsModule } from 'src/sections/sections.module';
import { PartProgressModule } from 'src/part-progress/part-progress.module';
import { AuthModule } from 'src/auth/auth.module';

@Module({
imports: [
forwardRef(() => SectionsModule),
QuizzesModule,
PartProgressModule,
AuthModule,
],
controllers: [PartsController],
providers: [PartsService, PartsRepository],
Expand Down
3 changes: 1 addition & 2 deletions src/sections/sections.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { SectionsService } from './sections.service';
import { SectionsController } from './sections.controller';
import { SectionsRepository } from './sections.repository';
import { PartsModule } from 'src/parts/parts.module';
import { AuthModule } from 'src/auth/auth.module';

@Module({
imports: [PartsModule, AuthModule],
imports: [PartsModule],
controllers: [SectionsController],
providers: [SectionsService, SectionsRepository],
exports: [SectionsService, SectionsRepository, PartsModule],
Expand Down

0 comments on commit 202b0ff

Please sign in to comment.