Skip to content

Commit

Permalink
Fix: #222 인증여부에 따라 헤더의 문구와 로그아웃 버튼 노출하도록 수정 (#223)
Browse files Browse the repository at this point in the history
* Fix: #222 인증여부에 따라 헤더의 문구와 로그아웃 버튼 노출하도록 수정

* Feat: #222 유저인증 되어 있지 않을 시 로그인 버튼 추가

* Chore: #222 로그인 화면 이동 시 replace 제거
  • Loading branch information
Yoonyesol authored Oct 19, 2024
1 parent 23a74c4 commit 7dab40e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logout } from '@services/authService';
import useToast from '@hooks/useToast';

export default function Header() {
const { userInfo: userInfoData, onLogout, clearUserInfo } = useStore();
const { userInfo: userInfoData, onLogout, clearUserInfo, isAuthenticated } = useStore();
const navigate = useNavigate();
const { toastSuccess } = useToast();

Expand All @@ -33,7 +33,9 @@ export default function Header() {
</Link>
</div>
<nav className="flex items-center">
<div className="tracking-tight text-white">{userInfoData.nickname}님의 Grow Up! 응원합니다.</div>
{isAuthenticated && (
<div className="tracking-tight text-white">{userInfoData.nickname}님의 Grow Up! 응원합니다.</div>
)}
<NavLink to="/" className="ml-10 hover:brightness-90">
{({ isActive }) => <FiHome className={`size-20 ${isActive ? 'text-selected' : 'text-white'}`} />}
</NavLink>
Expand All @@ -43,9 +45,9 @@ export default function Header() {
<button
type="button"
className="ml-10 h-20 rounded-md bg-white px-4 tracking-tight hover:brightness-90"
onClick={handleLogout}
onClick={isAuthenticated ? handleLogout : () => navigate('/signin')}
>
Logout
{isAuthenticated ? 'Logout' : 'Login'}
</button>
</nav>
</header>
Expand Down
9 changes: 1 addition & 8 deletions src/mocks/services/authServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,9 @@ const authServiceHandler = [

// 로그아웃 API
http.post(`${BASE_URL}/user/logout`, async ({ cookies }) => {
const { refreshToken, refreshTokenExpiresAt } = cookies;
const { refreshToken } = cookies;
const currentTime = Date.now();

if (!refreshToken || !refreshTokenExpiresAt) {
return HttpResponse.json(
{ message: '리프레시 토큰이 유효하지 않습니다. 다시 로그인해 주세요.' },
{ status: 401 },
);
}

return new HttpResponse(null, {
status: 200,
headers: {
Expand Down

0 comments on commit 7dab40e

Please sign in to comment.