Skip to content

Commit

Permalink
fix: auth로 navigate 되는 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
pepperdad committed Dec 18, 2024
1 parent 80bffe8 commit bb9fa8f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/routes/AuthRequierd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ const AuthRequired = ({ children }: AuthRequiredProps) => {

const { openAlert } = useModal();

useEffect(() => {
const user = localStorage.getItem("user");

if (!user || !JSON.parse(user)?.refreshToken) {
const user = localStorage.getItem("user");
if (user) {
if (!JSON.parse(user)?.role || !JSON.parse(user)?.refreshToken) {
// 기존에 존재하던 유저 role, refreshToken 유무로 토큰 제거 후 리로드
localStorage.clear();
openAlert({ title: "다시 로그인 해주세요." });
navigate("/auth");

window.location.reload();
return;
}
}

useEffect(() => {
const user = localStorage.getItem("user");
const interceptor = instance.interceptors.response.use(
(response) => response,
async (error) => {
Expand Down

0 comments on commit bb9fa8f

Please sign in to comment.