Skip to content

Commit

Permalink
chore :: pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wjzlskxk committed Nov 15, 2024
1 parent cae676f commit 760c8b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
6 changes: 4 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
# λͺ¨λ“  TypeScript νŒŒμΌμ„ κ²€μ‚¬ν•˜κ³ , μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” μž„ν¬νŠΈλ₯Ό 제거
if npx eslint --fix --ignore-pattern 'node_modules/' --ext .ts .; then
echo "검사 톡과"
exit 0
else
echo "μ—λŸ¬ λ°œμƒ!"
# 였λ₯˜ λ°œμƒ μ‹œ, μ‹€νŒ¨ν•œ 파일과 μ½”λ“œ 라인만 좜λ ₯
npx eslint --quiet --format=compact --ext .ts . | grep -E 'error|warn'
# 였λ₯˜ λ°œμƒ μ‹œ, μ‹€νŒ¨ν•œ 파일과 μ½”λ“œ 라인만 좜λ ₯ (error만 필터링)
npx eslint --quiet --format=compact --ext .ts . | grep 'error'
exit 1
fi
31 changes: 11 additions & 20 deletions src/libs/Axios/errorResponseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { AxiosError } from "axios";
import Token from "../Token/Token";
import {
ACCESS_TOKEN_KEY,
REFRESH_TOKEN_KEY,
REQUEST_TOKEN_KEY,
} from "constants/Token/Token.constant";
import { dodamAxios } from "./customAxios";
import AuthRepositoryImpl from "repositories/Auth/AuthRepositoryImpl";
import { AxiosError } from 'axios';
import Token from '../Token/Token';
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY, REQUEST_TOKEN_KEY } from 'constants/Token/Token.constant';
import { dodamAxios } from './customAxios';
import AuthRepositoryImpl from 'repositories/Auth/AuthRepositoryImpl';

export const errorResponseHandler = async (error: AxiosError) => {
if (error.response) {
Expand All @@ -17,21 +13,16 @@ export const errorResponseHandler = async (error: AxiosError) => {
const usingAccessToken = Token.getToken(ACCESS_TOKEN_KEY);
const usingRefreshToken = Token.getToken(REFRESH_TOKEN_KEY);

if (
usingAccessToken !== undefined &&
usingRefreshToken !== undefined &&
status === 401
) {
if (usingAccessToken !== undefined && usingRefreshToken !== undefined && status === 401) {
try {
const { data: newAccessToken } =
await AuthRepositoryImpl.refreshAccessToken(usingRefreshToken);
const { data: newAccessToken } = await AuthRepositoryImpl.refreshAccessToken(usingRefreshToken);

Token.setToken(ACCESS_TOKEN_KEY, newAccessToken);

dodamAxios.defaults.headers.common[
REQUEST_TOKEN_KEY
] = `Bearer ${newAccessToken}`;
} catch (error) {}
dodamAxios.defaults.headers.common[REQUEST_TOKEN_KEY] = `Bearer ${newAccessToken}`;
} catch (error) {
console.log(error);
}
}
}
return Promise.reject(error);
Expand Down
20 changes: 6 additions & 14 deletions src/libs/Axios/requestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { InternalAxiosRequestConfig } from "axios";
import Token from "../Token/Token";
import {
ACCESS_TOKEN_KEY,
REFRESH_TOKEN_KEY,
REQUEST_TOKEN_KEY,
} from "constants/Token/Token.constant";
import { InternalAxiosRequestConfig } from 'axios';
import Token from '../Token/Token';
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY, REQUEST_TOKEN_KEY } from 'constants/Token/Token.constant';

export const requestHandler = async (config: InternalAxiosRequestConfig) => {
if (
Token.getToken(ACCESS_TOKEN_KEY) !== undefined &&
Token.getToken(REFRESH_TOKEN_KEY) !== undefined
) {
config.headers[REQUEST_TOKEN_KEY] = `Bearer ${Token.getToken(
ACCESS_TOKEN_KEY
)}`;
if (Token.getToken(ACCESS_TOKEN_KEY) !== undefined && Token.getToken(REFRESH_TOKEN_KEY) !== undefined) {
config.headers[REQUEST_TOKEN_KEY] = `Bearer ${Token.getToken(ACCESS_TOKEN_KEY)}`;
} else {
console.log('Token is not exist');
}

return config;
Expand Down

0 comments on commit 760c8b9

Please sign in to comment.