Skip to content

Commit

Permalink
πŸ’š [Deploy] λΆˆν•„μš”ν•œ dev ν™˜κ²½ 검증 둜직 μ‚­μ œ (#637)
Browse files Browse the repository at this point in the history
## Summary
λΆˆν•„μš”ν•œ dev ν™˜κ²½ 검증 둜직 μ‚­μ œ
  • Loading branch information
nyeoni authored Jul 20, 2024
2 parents cb8c5e1 + 13861f6 commit d8bb40a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
19 changes: 1 addition & 18 deletions backend/src/auth/guard/user.guard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable, ExecutionContext, BadRequestException } from '@nestjs/common';
import { Injectable, ExecutionContext } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { Request } from 'express';
import { Observable } from 'rxjs';

import { AppConfigService } from '../../config/app/configuration.service';
Expand All @@ -13,22 +12,6 @@ export class UserGuard extends AuthGuard('user') {
}

canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
const skipUserGuard = this.reflector.get<boolean>('skipUserGuard', context.getHandler());
if (skipUserGuard) {
return true;
}
// 개발 ν™˜κ²½μ—μ„œλŠ” 토큰 검증을 ν•˜μ§€ μ•ŠμŒ
if (this.appConfigService.env === 'development') {
const request: Request = context.switchToHttp().getRequest<Request>();
const userId = request.headers['x-my-id'];
if (userId === undefined) {
throw new BadRequestException('x-my-id is undefined');
}
request.user = {
userId: +userId,
};
return true;
}
return super.canActivate(context);
}
}
2 changes: 1 addition & 1 deletion docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: postgres:15.3-alpine
restart: always
env_file:
- ./backend/.env
- ./backend/.env.local
volumes:
- db_data_local:/var/lib/postgresql/data
expose:
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/libs/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import axios, { AxiosError, AxiosResponse } from 'axios';
import { getAccessToken } from './auth';

const createAxiosInstance = () => {
const isDev = import.meta.env.MODE === 'development';
const token = getAccessToken();
const headers = isDev ? { 'x-my-id': token ?? '1' } : { Authorization: `Bearer ${token}` };
const headers = { Authorization: `Bearer ${token}` };

return axios.create({ baseURL: import.meta.env.VITE_API_URL, headers, timeout: 100000, withCredentials: true });
};
Expand Down
19 changes: 5 additions & 14 deletions frontend/src/libs/api/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@ import { io } from 'socket.io-client';
import { getAccessToken } from './auth';

const createSocketInstance = () => {
const isDev = import.meta.env.MODE === 'development';
const token = getAccessToken();

if (isDev) {
return io(import.meta.env.VITE_BASE_URL, {
autoConnect: false,
extraHeaders: { 'x-my-id': token ?? '1' },
withCredentials: true,
});
} else {
return io(import.meta.env.VITE_BASE_URL, {
autoConnect: false,
auth: { token: `${token ?? ''}` },
withCredentials: true,
});
}
return io(import.meta.env.VITE_BASE_URL, {
autoConnect: false,
auth: { token: `${token ?? ''}` },
withCredentials: true,
});
};

export const socket = createSocketInstance();
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ghostpong",
"version": "1.0.0",
"scripts": {
"start": "docker-compose -f ./docker-compose.local.yml up",
"restart": "docker-compose -f ./docker-compose.local.yml up --build",
"stop": "docker-compose down"
},
"author": "",
"license": "ISC"
}

0 comments on commit d8bb40a

Please sign in to comment.