From 796b5fcd86a1a4788f755d2b2292f95b44a1045e Mon Sep 17 00:00:00 2001
From: leejin_rho <tbdpapdl@gmail.com>
Date: Mon, 1 Jul 2024 22:01:47 +0900
Subject: [PATCH] feat: set isAdmin atom at localStorage

---
 apis/client.ts  | 12 ++++++++++++
 pages/login.tsx |  7 ++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

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("/");