Skip to content

Commit

Permalink
Merge pull request #611 from boostcampwm2023/BE/feature/#100
Browse files Browse the repository at this point in the history
어드민 개발
  • Loading branch information
Dltmd202 authored Dec 30, 2023
2 parents 67e9985 + 41aa580 commit e51c725
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 6 deletions.
170 changes: 170 additions & 0 deletions BE/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions BE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"cache-manager-redis-store": "^3.0.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"ejs": "^3.1.9",
"joi": "^17.11.0",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.6.3",
Expand All @@ -50,6 +52,7 @@
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.6",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/multer": "^1.4.11",
Expand Down
Binary file added BE/public/AppIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions BE/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<title>Home</title>
<meta charset="UTF-8">
<link rel="icon" href="/AppIcon.png" type="image/x-icon">
</head>
<body>
<p>모티 앱 v0.0 <a href="itms-services://?action=download-manifest&amp;url=https://kr.object.ncloudstorage.com/motimate-deploy/manifest.plist">Download</a></p>
Expand Down
25 changes: 25 additions & 0 deletions BE/public/js/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.addEventListener('DOMContentLoaded', () => {
const logoutButton = document.getElementById('logout');
const token = getCookie('access-token');
if (!token) {
logoutButton.style.display = 'none';
} else {
logoutButton.addEventListener('click', async () => {
document.cookie =
'access-token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
alert('로그아웃 되었습니다.');
window.location.href = '/operate/login';
});
}
});

const getCookie = (name) => {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.startsWith(name + '=')) {
return cookie.substring(name.length + 1);
}
}
return null;
};
7 changes: 5 additions & 2 deletions BE/src/admin/controller/admin-rest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
HttpCode,
Post,
Query,
Res,
UseGuards,
} from '@nestjs/common';
import { AdminService } from '../application/admin.service';
import { AccessTokenGuard } from '../../auth/guard/access-token.guard';
import { AdminRegister } from '../dto/admin-register';
import { AuthenticatedUser } from '../../auth/decorator/athenticated-user.decorator';
import { User } from '../../users/domain/user.domain';
Expand All @@ -21,6 +21,7 @@ import {
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { Response } from 'express';
import { AdminTokenGuard } from '../../auth/guard/admin-token.guard';

@Controller('/api/v1/admin')
Expand All @@ -30,7 +31,7 @@ export class AdminRestController {

@HttpCode(204)
@Post('register')
@UseGuards(AccessTokenGuard)
@UseGuards(AdminTokenGuard)
@ApiOperation({
summary: '어드민 등록 요청 API',
description: '어드민 등록 요청',
Expand Down Expand Up @@ -60,8 +61,10 @@ export class AdminRestController {
})
async loginAdmin(
@Body() loginRequest: AdminLogin,
@Res({ passthrough: true }) response: Response,
): Promise<ApiData<AdminToken>> {
const adminToken = await this.adminService.loginAdmin(loginRequest);
response.cookie('access-token', adminToken);
return ApiData.success(AdminToken.from(adminToken));
}

Expand Down
6 changes: 5 additions & 1 deletion BE/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { CacheModule } from '@nestjs/cache-manager';
import { redisModuleOptions } from '../config/redis';
import type { RedisClientOptions } from 'redis';
import { AvatarHolder } from './application/avatar.holder';
import { AdminTokenGuard } from './guard/admin-token.guard';
import { AdminPageTokenGuard } from './guard/admin-page-token.guard';

@Global()
@Module({
Expand All @@ -34,7 +36,9 @@ import { AvatarHolder } from './application/avatar.holder';
UserCodeGenerator,
AccessTokenGuard,
AvatarHolder,
AdminTokenGuard,
AdminPageTokenGuard,
],
exports: [JwtUtils, AccessTokenGuard],
exports: [JwtUtils, AccessTokenGuard, AdminTokenGuard, AdminPageTokenGuard],
})
export class AuthModule {}
1 change: 1 addition & 0 deletions BE/src/auth/exception/UnAuthorized-Admin-Page.exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class UnAuthorizedAdminPageException extends Error {}
Loading

0 comments on commit e51c725

Please sign in to comment.