Skip to content

Commit

Permalink
feat: set isAdmin atom at localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
leejin-rho committed Jul 1, 2024
1 parent ada7aaa commit 796b5fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions apis/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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("/");
Expand Down

0 comments on commit 796b5fc

Please sign in to comment.