Skip to content

Commit

Permalink
Merge pull request #87 from uzzulManagement/dev
Browse files Browse the repository at this point in the history
feat: instance 수정
  • Loading branch information
YoujungSon authored Mar 27, 2023
2 parents 785159c + 83058b6 commit 0cbc1c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/apis/assetInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export const AxiosInstance = axios.create({
Accept: 'application/json',
},
});
export const AuthAxiosInstance = axios.create({
baseURL: process.env.REACT_APP_BASE_URL,
headers: {
Accept: 'application/json',
},
});

AxiosInstance.interceptors.request.use(
function (config) {
Expand Down Expand Up @@ -40,11 +46,21 @@ AxiosInstance.interceptors.response.use(
AxiosInstance.defaults.headers.common.Authorization = `Bearer ${tokenData.token}`;
return AxiosInstance(originalRequest);
}
if (error.response.data.errorMessage === 'The token is incorrect. Please login again.') {

return Promise.reject(error);
},
);
AuthAxiosInstance.interceptors.response.use(
function (response) {
return response;
},
async (error) => {
if (error.response.status === 401) {
alert('로그인이 만료되었습니다. 다시 로그인해주세요.');
localStorage.clear();
window.location.href = '/';
}

return Promise.reject(error);
},
);
4 changes: 2 additions & 2 deletions src/apis/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosInstance } from './assetInstance';
import { AuthAxiosInstance, AxiosInstance } from './assetInstance';

type readuserType = {
token: string;
Expand All @@ -7,7 +7,7 @@ type readuserType = {
};

export const refreshToken = async (token: string) => {
const response = await AxiosInstance.post('/authtoken', { token });
const response = await AuthAxiosInstance.post('/authtoken', { token });
return response;
};
export const readuser = async ({ token, email, password }: readuserType) => {
Expand Down

2 comments on commit 0cbc1c0

@vercel
Copy link

@vercel vercel bot commented on 0cbc1c0 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0cbc1c0 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.