From 232a7822bc706ce061d20f583c431623b8ddbfd3 Mon Sep 17 00:00:00 2001 From: lybell-art Date: Mon, 12 Aug 2024 18:31:48 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EB=A9=94=EC=9D=B8=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=ED=86=A0=ED=81=B0/=EC=96=B4=EB=93=9C=EB=AF=BC?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=ED=86=A0=ED=81=B0=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC,=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20=ED=99=98?= =?UTF-8?q?=EC=98=81=ED=95=A9=EB=8B=88=EB=8B=A4=EA=B0=80=20=EC=A6=89?= =?UTF-8?q?=EC=8B=9C=20=EC=97=86=EC=96=B4=EC=A7=80=EB=8D=98=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/constants.js | 3 ++- src/common/dataFetch/tokenSaver.js | 20 ++++++++++---------- src/common/modal/modal.jsx | 17 ++++++++++------- src/mainPage/shared/auth/store.js | 5 +++-- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/common/constants.js b/src/common/constants.js index f8ec92ef..609e51e2 100644 --- a/src/common/constants.js +++ b/src/common/constants.js @@ -1,2 +1,3 @@ export const EVENT_ID = "0"; -export const TOKEN_ID = "AWESOME_ORANGE_ACCESS_TOKEN"; \ No newline at end of file +export const SERVICE_TOKEN_ID = "AWESOME_ORANGE_ACCESS_TOKEN"; +export const ADMIN_TOKEN_ID = "AWESOME_ORANGE_ADMIN_ACCESS_TOKEN"; \ No newline at end of file diff --git a/src/common/dataFetch/tokenSaver.js b/src/common/dataFetch/tokenSaver.js index 67eea568..8bd9ae3d 100644 --- a/src/common/dataFetch/tokenSaver.js +++ b/src/common/dataFetch/tokenSaver.js @@ -1,31 +1,31 @@ -import { TOKEN_ID } from "@common/constants.js"; - class TokenSaver { initialized = false; token = null; - init() { + tokenId = null; + init(tokenId) { if (typeof window === "undefined") return; - this.token = localStorage.getItem(TOKEN_ID) ?? null; + this.tokenId = tokenId; + this.token = localStorage.getItem(this.tokenId) ?? null; this.initialized = true; } - get() { + get(tokenId = this.tokenId) { if (this.initialized) return this.token; - this.init(); + this.init(tokenId); return this.token; } set(token) { this.token = token; - if (typeof window !== "undefined") localStorage.setItem(TOKEN_ID, token); + if (typeof window !== "undefined") localStorage.setItem(this.tokenId, token); this.initialzed = true; } - has() { + has(tokenId = this.tokenId) { if (this.initialized) return this.token !== null; - this.init(); + this.init(tokenId); return this.token !== null; } remove() { this.token = null; - if (typeof window !== "undefined") localStorage.removeItem(TOKEN_ID); + if (typeof window !== "undefined") localStorage.removeItem(this.tokenId); this.initialzed = true; } } diff --git a/src/common/modal/modal.jsx b/src/common/modal/modal.jsx index 6cbd318b..d98f9b4e 100644 --- a/src/common/modal/modal.jsx +++ b/src/common/modal/modal.jsx @@ -1,6 +1,5 @@ import { createContext, useCallback, useEffect, useState, useRef } from "react"; import useModalStore, { closeModal } from "./store.js"; -import { delay } from "@common/utils.js"; export const ModalCloseContext = createContext(() => { console.log("모달이 닫힙니다."); @@ -10,12 +9,16 @@ function Modal({ layer }) { const timeoutRef = useRef(null); const child = useModalStore(layer); const [opacity, setOpacity] = useState(0); - const close = useCallback(async () => { - setOpacity(0); - if (timeoutRef.current === null) { - await delay(150); - closeModal(layer); - } + const close = useCallback(() => { + return new Promise( (resolve)=>{ + setOpacity(0); + + if (timeoutRef.current !== null) return resolve(); + timeoutRef.current = setTimeout( ()=>{ + closeModal(layer); + resolve(); + }, 150 ); + } ); }, [layer]); useEffect(() => { diff --git a/src/mainPage/shared/auth/store.js b/src/mainPage/shared/auth/store.js index 133d016a..c57bb7b7 100644 --- a/src/mainPage/shared/auth/store.js +++ b/src/mainPage/shared/auth/store.js @@ -1,5 +1,6 @@ import { create } from "zustand"; import tokenSaver from "@common/dataFetch/tokenSaver.js"; +import { SERVICE_TOKEN_ID } from "@common/constants.js"; const userStore = create(() => ({ isLogin: false, @@ -23,8 +24,8 @@ export function logout() { } export function initLoginState() { - tokenSaver.init(); - const token = tokenSaver.get(); + tokenSaver.init(SERVICE_TOKEN_ID); + const token = tokenSaver.get(SERVICE_TOKEN_ID); const userName = parseTokenToUserName(token); if (token === null) userStore.setState(() => ({ isLogin: false, userName: "" }));