Skip to content

Commit

Permalink
Merge pull request #80 from 2024-Team-Techeer-Salon/develop
Browse files Browse the repository at this point in the history
[build] main update
  • Loading branch information
YunJuwon0825 authored Jul 7, 2024
2 parents fd4e4f7 + b067874 commit 70c339e
Show file tree
Hide file tree
Showing 29 changed files with 539 additions and 405 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Frontend CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:

build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20.14.0'

- name: Install yarn
run: npm install -g yarn

- name: Cache yarn dependencies
uses: actions/cache@v3
with:
path: |
~/.yarn/cache
node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install

- name: Build project
run: yarn build


# - name: Trigger Docker CI/CD
# run: |
# curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github.v3+json" \
# https://api.github.com/repos/your-org/docker-repo/dispatches \
# -d '{"event_type":"frontend_updated"}'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

.idea
9 changes: 3 additions & 6 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable no-console */

export function GoogleLogin() {
try {
window.location.href = `${process.env.NEXT_PUBLIC_BASE_URL}/oauth2/authorization/google`;
} catch (error) {
console.error('구글 로그인 에러 : ', error);
throw new Error('구글 로그인 에러 : ', error || '');
}
}

export function KakaoLogin() {
try {
window.location.href = `${process.env.NEXT_PUBLIC_BASE_URL}/oauth2/authorization/kakao`;
} catch (error) {
console.error('카카오 로그인 에러 : ', error);
throw new Error('카카오 로그인 에러 : ', error || '');
}
}

export function NaverLogin() {
try {
window.location.href = `${process.env.NEXT_PUBLIC_BASE_URL}/oauth2/authorization/naver`;
} catch (error) {
console.error('네이버 로그인 에러 : ', error);
throw new Error('네이버 로그인 에러 : ', error || '');
}
}
92 changes: 64 additions & 28 deletions src/api/axios.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-param-reassign */
/* eslint-disable consistent-return */
/* eslint-disable no-underscore-dangle */
import axios from 'axios';
import { getCookie, setCookie } from '@/app/cookies.tsx';

Expand All @@ -11,12 +12,12 @@ const reIssuedToken = async () => {
const response = await axios.post(
`${BASE_URL}/reissue`,
{
access_token: getCookie('accessToken'), // 액세스 토큰을 사용하고 있으나, 일반적으로는 사용하지 않습니다.
refresh_token: getCookie('refreshToken'), // 리프레시 토큰
access_token: getCookie('accessToken'),
refresh_token: getCookie('refreshToken'),
},
{
headers: {
'Content-Type': 'application/json', // 요청의 본문 타입을 지정
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
withCredentials: true, // CORS 요청 시 쿠키를 포함
Expand All @@ -30,40 +31,48 @@ const reIssuedToken = async () => {
}
return response.data;
} catch (error) {
console.error('Token reissue error:', error);
throw error; // 오류를 상위로 전파하여 호출자가 이를 처리할 수 있도록 합니다.
setCookie('accessToken', '');
setCookie('refreshToken', '');
}
};

const api = axios.create({
withCredentials: true,
baseURL: BASE_URL, // 기본 URL 설정
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
});

// 요청 인터셉터를 추가하여 모든 요청에 최신 토큰을 포함시킵니다.
api.interceptors.request.use(
(config) => {
const token = getCookie('accessToken'); // 요청 직전에 액세스 토큰을 쿠키에서 가져옵니다.
config.headers.Authorization = `Bearer ${token}`;
config.headers['Content-Type'] = 'application/json';
return config;
},
(error) => Promise.reject(error),
);

api.interceptors.response.use(
(response) => response, // 성공 응답은 그대로 반환
async (error) => {
const originalRequest = error.config;
if (error.response.status === 401 && !originalRequest._retry) {
originalRequest._retry = true; // 재요청 플래그를 설정하여 무한 루프 방지
try {
const data = await reIssuedToken(); // 토큰 재발급 함수 호출
// 재발급 받은 토큰으로 요청 헤더 설정
api.defaults.headers.common.Authorization = `Bearer ${data.data.access_token}`;
originalRequest.headers.Authorization = `Bearer ${data.data.access_token}`;
if (accessToken !== undefined) {
const originalRequest = error.config;
if (error.response.status === 401 && !originalRequest._retry) {
originalRequest._retry = true; // 재요청 플래그를 설정하여 무한 루프 방지
try {
const data = await reIssuedToken(); // 토큰 재발급 함수 호출
// 재발급 받은 토큰으로 요청 헤더 설정
api.defaults.headers.common.Authorization = `Bearer ${data.data.access_token}`;
originalRequest.headers.Authorization = `Bearer ${data.data.access_token}`;

return api(originalRequest); // 원래 요청 재시도
} catch (refreshError) {
console.error('Failed to refresh token:', refreshError);
return Promise.reject(refreshError);
return api(originalRequest); // 원래 요청 재시도
} catch (refreshError) {
return Promise.reject(refreshError);
}
}
}

return Promise.reject(error);
return Promise.reject(error);
}
},
);

Expand All @@ -72,8 +81,35 @@ export { api };
export const formApi = axios.create({
withCredentials: true,
baseURL: BASE_URL,
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${accessToken}`,
},
});

formApi.interceptors.request.use(
(config) => {
const token = getCookie('accessToken');
config.headers.Authorization = `Bearer ${token}`;
return config;
},
(error) => Promise.reject(error),
);

formApi.interceptors.response.use(
(response) => response,
async (error) => {
if (accessToken !== undefined) {
const originalRequest = error.config;
if (error.response.status === 401 && !originalRequest._retry) {
originalRequest._retry = true;
try {
const data = await reIssuedToken();
formApi.defaults.headers.common.Authorization = `Bearer ${data.data.access_token}`;
originalRequest.headers.Authorization = `Bearer ${data.data.access_token}`;

return formApi(originalRequest);
} catch (refreshError) {
return Promise.reject(refreshError);
}
}
return Promise.reject(error);
}
},
);
19 changes: 19 additions & 0 deletions src/api/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { api } from './axios.config.ts';

export const deleteChat = async (chatId: number) => {
try {
const response = await api.delete(`chattings/rooms/${chatId}`);
return response.data;
} catch (error) {
throw new Error('chat delete api request error : ', error || '');
}
};

export const getChats = async (meetingId: number) => {
try {
const response = await api.get(`/chats/${meetingId}`);
return response.data.data;
} catch (error) {
throw new Error('chat get api request error : ', error || '');
}
};
23 changes: 0 additions & 23 deletions src/api/check.ts

This file was deleted.

10 changes: 3 additions & 7 deletions src/api/kakao.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable consistent-return */
/* eslint-disable no-console */
import axios from 'axios';

export async function searchAddress(
export default async function searchAddress(
keyword: string,
lat: number,
lng: number,
page: number,
size: number,
) {
if (!keyword) {
return;
return null;
}
try {
const response = await axios.get(
Expand All @@ -30,9 +27,8 @@ export async function searchAddress(
},
},
);
console.log('searchAddress response : ', response.data);
return response.data;
} catch (error) {
console.error('searchAddress error : ', error);
throw new Error('kakao search address api request error : ', error || '');
}
}
Loading

0 comments on commit 70c339e

Please sign in to comment.