-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/epigram5-9/epigram into mer…
…ge/FE-54
- Loading branch information
Showing
25 changed files
with
741 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { AddEpigramRequestType, AddEpigramResponseType } from '@/schema/addEpigram'; | ||
import httpClient from '.'; | ||
|
||
const postEpigram = async (request: AddEpigramRequestType): Promise<AddEpigramResponseType> => { | ||
const response = await httpClient.post<AddEpigramResponseType>('/epigrams', request); | ||
return response.data; | ||
}; | ||
|
||
export default postEpigram; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PostSigninRequestType, PostSigninResponseType } from '@/schema/auth'; | ||
import httpClient from '.'; | ||
|
||
const postSignin = async (request: PostSigninRequestType): Promise<PostSigninResponseType> => { | ||
const response = await httpClient.post('/auth/signIn', request); | ||
return response.data; | ||
}; | ||
|
||
export default postSignin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,52 @@ | ||
import axios from 'axios'; | ||
import qs from 'qs'; | ||
|
||
// NOTE: 토큰 가져오는 함수 | ||
const getToken = () => | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjIsInRlYW1JZCI6IjUtOSIsInNjb3BlIjoiYWNjZXNzIiwiaWF0IjoxNzIyMDUwNTY3LCJleHAiOjE3MjIwNTIzNjcsImlzcyI6InNwLWVwaWdyYW0ifQ.uD0OZu7OFxBl3XqHGqNaqCLCDcE9BZant875W9tVr0o'; | ||
|
||
// NOTE: axios 선언 | ||
const httpClient = axios.create({ | ||
baseURL: process.env.NEXT_PUBLIC_BASE_URL, | ||
paramsSerializer: (parameters) => qs.stringify(parameters, { arrayFormat: 'repeat', encode: false }), | ||
}); | ||
|
||
// NOTE: 요청 인터셉터 추가 | ||
httpClient.interceptors.request.use( | ||
(config) => { | ||
const newConfig = { ...config }; | ||
const token = getToken(); | ||
if (token) { | ||
newConfig.headers.Authorization = `Bearer ${token}`; | ||
} | ||
// NOTE: eslint-disable no-param-reassign 미해결로 인한 설정 | ||
httpClient.interceptors.request.use((config) => { | ||
const accessToken = localStorage.getItem('accessToken'); | ||
/* eslint-disable no-param-reassign */ | ||
if (accessToken) config.headers.Authorization = `Bearer ${accessToken}`; | ||
/* eslint-enable no-param-reassign */ | ||
return config; | ||
}); | ||
|
||
if (newConfig.data instanceof FormData) { | ||
newConfig.headers['Content-Type'] = 'multipart/form-data'; | ||
} else { | ||
newConfig.headers['Content-Type'] = 'application/json'; | ||
} | ||
httpClient.interceptors.response.use( | ||
(response) => response, | ||
|
||
return newConfig; | ||
(error) => { | ||
if (error.response && error.response.status === 401) { | ||
const refreshToken = localStorage.getItem('refreshToken'); | ||
|
||
if (!refreshToken) { | ||
window.location.href = '/auth/SignIn'; | ||
return Promise.reject(error); | ||
} | ||
|
||
return httpClient | ||
.post('/auth/refresh-token', null, { | ||
headers: { Authorization: `Bearer ${refreshToken}` }, | ||
}) | ||
.then((response) => { | ||
const { accessToken, refreshToken: newRefreshToken } = response.data; | ||
localStorage.setItem('accessToken', accessToken); | ||
localStorage.setItem('refreshToken', newRefreshToken); | ||
|
||
const originalRequest = error.config; | ||
return httpClient(originalRequest); | ||
}) | ||
.catch(() => { | ||
window.location.href = '/auth/SignIn'; | ||
return Promise.reject(error); | ||
}); | ||
} | ||
return Promise.reject(error); | ||
}, | ||
(error) => Promise.reject(error), | ||
); | ||
|
||
export default httpClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.