From 675e8597850aae271a062a3e839a9c919fbeac8d Mon Sep 17 00:00:00 2001 From: Sungu Kim <108677235+haegu97@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:10:43 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F[Refactor]=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EB=A7=8C=EB=A3=8C=EA=B8=B0=ED=95=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/auth/utils/cookies.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/features/auth/utils/cookies.ts b/src/features/auth/utils/cookies.ts index 3b298d45..ca37c320 100644 --- a/src/features/auth/utils/cookies.ts +++ b/src/features/auth/utils/cookies.ts @@ -1,5 +1,7 @@ export const setCookie = (name: string, value: string) => { - document.cookie = `${name}=${value};path=/`; + const expirationDate = new Date(); + expirationDate.setTime(expirationDate.getTime() + 60 * 60 * 1000); + document.cookie = `${name}=${value};path=/;expires=${expirationDate.toUTCString()}`; }; export const getCookie = (name: string): string | null => { From 4dd5eaf1d59326e6ea9499dda09f25bc061da113 Mon Sep 17 00:00:00 2001 From: Sungu Kim <108677235+haegu97@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:11:27 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F[Refactor]=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=EA=B3=A0=EC=B9=A8=20=EC=8B=9C=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=9C=A0=EB=AC=B4=20=ED=99=95=EC=9D=B8=20#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/header/HeaderBar.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/header/HeaderBar.tsx b/src/components/header/HeaderBar.tsx index b6084a94..65e303a3 100644 --- a/src/components/header/HeaderBar.tsx +++ b/src/components/header/HeaderBar.tsx @@ -1,6 +1,6 @@ 'use client'; -import React from 'react'; +import React, { useEffect } from 'react'; import NavButton from './NavButton'; import { NAV_ITEMS } from '@/constants/navigation'; import { usePathname, useRouter } from 'next/navigation'; @@ -10,9 +10,13 @@ import { logout } from '@/features/auth/api/auth'; function HeaderBar() { const pathname = usePathname(); - const { isLoggedIn, user } = useAuthStore(); + const { isLoggedIn, user, checkLoginStatus } = useAuthStore(); const router = useRouter(); + useEffect(() => { + checkLoginStatus(); + }, [checkLoginStatus]); + const handleDropDownChange = async (value: string | undefined) => { if (value === 'LOGOUT') { try { From e1961d89e3e5a142f3ed255c0a338bd39e05eaed Mon Sep 17 00:00:00 2001 From: Sungu Kim <108677235+haegu97@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:23:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85[Test]=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/header/HeaderBar.test.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/header/HeaderBar.test.tsx b/src/components/header/HeaderBar.test.tsx index 3a0ea83e..71aafdfa 100644 --- a/src/components/header/HeaderBar.test.tsx +++ b/src/components/header/HeaderBar.test.tsx @@ -61,14 +61,18 @@ describe('HeaderBar 컴포넌트 테스트', () => { describe('로그인 상태에 따른 버튼 렌더링', () => { beforeEach(() => { jest.clearAllMocks(); - useAuthStore.setState({ isLoggedIn: false, user: null }); + useAuthStore.setState({ + isLoggedIn: false, + user: null, + checkLoginStatus: jest.fn(), + }); }); it('로그인 상태일 때 드롭다운 버튼이 렌더링되어야 한다', () => { useAuthStore.setState({ isLoggedIn: true, user: { - image: '/images/default-profile.png', + image: '/images/profile.png', teamId: 'team-id', id: 1, email: 'user@example.com', @@ -77,6 +81,7 @@ describe('로그인 상태에 따른 버튼 렌더링', () => { createdAt: new Date(), updatedAt: new Date(), }, + checkLoginStatus: jest.fn(), }); render();