Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ’š [Chore] ๋กœ๊ทธ์ธ ๊ตฌํ˜„์™„๋ฃŒ๋กœ ์ธํ•œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์˜ x-my-id ๊ฒ€์ฆ ๋กœ์ง ์‚ญ์ œ #636

Merged
merged 4 commits into from
Jul 20, 2024
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"
}
Loading