Skip to content

Commit

Permalink
fix: catch 4002 error and logout
Browse files Browse the repository at this point in the history
  • Loading branch information
shj1081 committed Feb 11, 2025
1 parent 7099b86 commit d4d21f9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useAuth } from "../Auth";

export function Header() {
const [isOpen, setIsOpen] = useState(false);
const { isLoggedIn } = useAuth();
const { isLoggedIn, logout } = useAuth(); // Destructure logout here
const router = useRouter();
const pathname = usePathname(); // 현재 경로 가져오기

Expand All @@ -28,6 +28,11 @@ export function Header() {
if (error.response?.data?.code === 4001) {
router.push("/register");
}

// 예: code 4002이 응답되면 로그아웃 수행
if (error.response?.data?.code === 4002) {
logout();
}
});
}
}, [isLoggedIn, router, pathname]);
Expand Down

0 comments on commit d4d21f9

Please sign in to comment.