Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/header/HeaderBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -77,6 +81,7 @@ describe('로그인 상태에 따른 버튼 렌더링', () => {
createdAt: new Date(),
updatedAt: new Date(),
},
checkLoginStatus: jest.fn(),
});

render(<HeaderBar />);
Expand Down
8 changes: 6 additions & 2 deletions src/components/header/HeaderBar.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/features/auth/utils/cookies.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
Loading