diff --git a/apis/client.ts b/apis/client.ts index 04a1d94..3e200f3 100644 --- a/apis/client.ts +++ b/apis/client.ts @@ -22,6 +22,18 @@ const getTokenFromLocalStorage = () => { return accessToken; }; +export const setIsAdminAtLocalStorage = (is_admin: string) => { + localStorage.setItem("is_admin", is_admin); +}; + +const getIsAdminFromLocalStorage = () => { + const isAdmin = localStorage.getItem("is_admin"); + if (!isAdmin) { + return null; + } + return isAdmin; +}; + const client = axios.create({ baseURL: process.env.NEXT_PUBLIC_API_URL, withCredentials: true, diff --git a/pages/login.tsx b/pages/login.tsx index 2af7d8c..981c1a4 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -5,7 +5,11 @@ import { useRouter } from "next/router"; import Button from "@/components/Button"; import LogoLetterIcon from "@/public/svgs/LogoLetter.svg"; import { useMutation } from "@tanstack/react-query"; -import { ResponseBody, setTokenFromLocalStorage } from "@/apis/client"; +import { + ResponseBody, + setIsAdminAtLocalStorage, + setTokenFromLocalStorage, +} from "@/apis/client"; import { SignIn } from "@/apis/auth"; import { atom, useAtom } from "jotai"; import { isAdminAtom } from "@/utils/atom"; @@ -55,6 +59,7 @@ const Login: NextPage = () => { const refreshToken = data.result.refreshToken; const isAdmin = data.result.isAdmin; setIsAdmin(isAdmin); + setIsAdminAtLocalStorage(isAdmin); setTokenFromLocalStorage(accessToken); router.push("/");