Skip to content

Commit

Permalink
♻️ : #386 - 토큰 비교 로직 변경 및 함수 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
qkdl60 committed Jan 1, 2024
1 parent c9f6570 commit c1cca84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/apis/axiosInstanceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { NETWORK } from '@/constants/api';
import { COOKIE_MAX_AGE } from '@/constants/cookie';
import { ErrorResponseData } from '@/types/apis/ErrorResponseData';
import { checkTokenExp } from '@/utils/checkTokenExp';
import { checkIsTokenExpired } from '@/utils/checkIsTokenExpired';
import axios, { AxiosError, InternalAxiosRequestConfig } from 'axios';
import { getCookie, setCookie } from 'cookies-next';
import { postReissue } from '@apis/client/postReissue';
Expand Down Expand Up @@ -54,8 +54,8 @@ axiosInstanceClient.interceptors.response.use(
const accessToken = JSON.parse(auth).accessToken;
const refreshToken = JSON.parse(auth).refreshToken;

const isExpiredAccessToken = !checkTokenExp(accessToken);
const isExpiredRefreshToken = !checkTokenExp(refreshToken);
const isExpiredAccessToken = checkIsTokenExpired(accessToken);
const isExpiredRefreshToken = checkIsTokenExpired(refreshToken);
if (isExpiredAccessToken && !isExpiredRefreshToken) {
try {
const {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/checkIsTokenExpired.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { decodeJWT } from './decodeJWT';

export const checkIsTokenExpired = (token: string) => {
const exp = decodeJWT(token).exp;
const now = Date.now();
const nowLength = now.toString().length;
const expStr = exp.toString().padEnd(nowLength, '0');

return Number(expStr) < now;
};
8 changes: 0 additions & 8 deletions src/utils/checkTokenExp.ts

This file was deleted.

0 comments on commit c1cca84

Please sign in to comment.