-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ :: 내 리뷰 페이지 동문검증로직, axios 인터셉터 수정
- Loading branch information
1 parent
779e2d0
commit 2cf4446
Showing
19 changed files
with
97 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ config.json | |
dist | ||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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,24 @@ | ||
import { useEffect } from "react"; | ||
import { ACCESS_TOKEN_KEY } from "@src/constants/Auth/auth.constant"; | ||
import Token from "@src/libs/Token/Token"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useRollingToast } from "@stubee2/stubee2-rolling-toastify"; | ||
import { jwtDecoding } from "@src/utils/Auth/jwtDecoding"; | ||
|
||
const useAlumniCheck = () => { | ||
const navigate = useNavigate(); | ||
const { rollingToast } = useRollingToast(); | ||
const memberRole = jwtDecoding("authority"); | ||
|
||
useEffect(() => { | ||
const checkAlumni = () => { | ||
if (Token.getToken(ACCESS_TOKEN_KEY) && memberRole === "TEMP") { | ||
rollingToast("동문 인증이 필요한 기능입니다.", "warning"); | ||
navigate("/"); | ||
} | ||
}; | ||
checkAlumni(); | ||
}, [navigate]); | ||
}; | ||
|
||
export default useAlumniCheck; |
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
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
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
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
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
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,37 +1,20 @@ | ||
import { InternalAxiosRequestConfig } from "axios"; | ||
import { AxiosRequestConfig } from "axios"; | ||
import { | ||
ACCESS_TOKEN_KEY, | ||
REFRESH_TOKEN_KEY, | ||
REQUEST_TOKEN_KEY, | ||
} from "@src/constants/Auth/auth.constant"; | ||
import Token from "../Token/Token"; | ||
import { rollingAxios } from "./customAxios"; | ||
import dayjs from "dayjs"; | ||
import authRepositoryImpl from "@src/repositories/Auth/auth.repositoryImpl"; | ||
import { jwtDecoding } from "@src/utils/Auth/jwtDecoding"; | ||
|
||
export const requestHandler = async (config: InternalAxiosRequestConfig) => { | ||
let access_token = Token.getToken(ACCESS_TOKEN_KEY); | ||
export const requestHandler = (config: AxiosRequestConfig) => { | ||
const access_token = Token.getToken(ACCESS_TOKEN_KEY); | ||
const refresh_token = Token.getToken(REFRESH_TOKEN_KEY); | ||
const expirationAt = new Date(Number(jwtDecoding("exp")) * 1000); // 1000을 곱해 밀리초 단위로 변환 | ||
|
||
// 만료시간과 현재 시간을 비교하여 0 미만이면 어세스 토큰이 만료된 것이므로 아래 조건문 실행 | ||
if (dayjs(expirationAt).diff(dayjs()) < 0 && refresh_token) { | ||
try { | ||
const { accessToken: newAccessToken } = | ||
await authRepositoryImpl.postRefreshToken({ | ||
refreshToken: refresh_token, | ||
}); | ||
Token.setToken(ACCESS_TOKEN_KEY, newAccessToken); | ||
access_token = newAccessToken; | ||
} catch (e) { | ||
// 요청을 실패하면 리프레쉬 토큰도 만료이므로 아래처럼 처리 | ||
Token.clearToken(); | ||
window.alert("토큰이 만료되었습니다!"); | ||
window.location.href = "/"; | ||
} | ||
if (access_token || refresh_token) { | ||
config.headers = { | ||
"Content-Type": "application/json", | ||
[REQUEST_TOKEN_KEY]: `Bearer ${Token.getToken(ACCESS_TOKEN_KEY)}`, | ||
}; | ||
} | ||
|
||
rollingAxios.defaults.headers[REQUEST_TOKEN_KEY] = `Bearer ${access_token}`; | ||
return config; | ||
}; |
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
File renamed without changes.
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
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
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
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