From 9d48ffd342dc3302d55ab6e1d7db8762f0876a46 Mon Sep 17 00:00:00 2001 From: Yuno Date: Mon, 25 Nov 2024 21:26:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=B2=84=EA=B7=B8=EC=88=98=EC=A0=95:=20JWT?= =?UTF-8?q?=EB=A6=AC=ED=94=84=EB=A0=88=EC=8B=9C=EC=A4=91=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=EC=82=AC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JWT를 리프레시 하는중에 헤더의 프로필이 늦게 뜨는 문제 해결 --- src/app/main/_header.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/main/_header.tsx b/src/app/main/_header.tsx index b8e8377..cb099da 100644 --- a/src/app/main/_header.tsx +++ b/src/app/main/_header.tsx @@ -16,7 +16,6 @@ export default function MainHeader() { const fetchMyProfile = async () => { const user_handle = localStorage.getItem('user_handle'); - const now = Math.ceil(Date.now() / 1000); if (user_handle) { const res = await fetch('/api/db/fetch-my-profile', { @@ -28,11 +27,6 @@ export default function MainHeader() { } return; } - // JWT 리프레시로부터 1시간이 지난 경우 refresh 시도 - const last_token_refresh = Number.parseInt(localStorage.getItem('last_token_refresh') ?? '0'); - if (now - last_token_refresh > 3600) { - await refreshJwt(); - } const data = await res.json(); return data; } @@ -42,6 +36,17 @@ export default function MainHeader() { fetchMyProfile().then((r) => setUser(r)); }, []); + useEffect(() => { + const fn = async () => { + const now = Math.ceil(Date.now() / 1000); + // JWT 리프레시로부터 1시간이 지난 경우 refresh 시도 + const last_token_refresh = Number.parseInt(localStorage.getItem('last_token_refresh') ?? '0'); + if (now - last_token_refresh > 3600) { + await refreshJwt(); + } + }; + fn(); + }, []); return (
From 9c2074664b4e0783817949373e4bc1ed3f27254e Mon Sep 17 00:00:00 2001 From: Yuno Date: Mon, 25 Nov 2024 21:27:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EB=8C=80=EB=AC=B8=20useEffect?= =?UTF-8?q?=EC=97=90=20[]=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 7180ea0..7aadb94 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -168,7 +168,7 @@ export default function Home() { setIsLoading(false); }; fn(); - }); + }, []); return (