Skip to content

Commit

Permalink
feat: refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
punchanabu committed Oct 14, 2024
1 parent 353af01 commit f6c0bb7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Trophy, ReceiptText, Joystick, Coins } from "lucide-react";
import { useCoinStore } from "@/store/coin";
import { apiClient } from "@/api/axios";
import { AxiosError } from "axios";
import { refreshToken } from "@/utils/token";

export const Navbar = (props: { pagenow: string }) => {
const router = useRouter();
Expand All @@ -22,6 +23,8 @@ export const Navbar = (props: { pagenow: string }) => {
} catch (error) {
if (error instanceof AxiosError && error.response?.data?.error === "missing authorization header") {
router.push("/register");
} else if (error instanceof AxiosError && error.response?.data?.error === "invalid or expired token") {
refreshToken();
} else {
console.error("Error fetching user or refreshing coins:", error);
}
Expand Down

0 comments on commit f6c0bb7

Please sign in to comment.