diff --git a/src/components/ProfileDropdown.tsx b/src/components/ProfileDropdown.tsx
index c30a456..bd7afac 100644
--- a/src/components/ProfileDropdown.tsx
+++ b/src/components/ProfileDropdown.tsx
@@ -42,7 +42,7 @@ export default function ProfileDropdown({ nickname, profileImageUrl, onLogout }:
alt='프로필 이미지'
width={32}
height={32}
- className='rounded-full border border-gray-300'
+ className='w-32 h-32 rounded-full border border-gray-300 object-cover'
/>
) : (
diff --git a/src/hooks/useMyPageQueries.ts b/src/hooks/useMyPageQueries.ts
index 55f1340..45ce17a 100644
--- a/src/hooks/useMyPageQueries.ts
+++ b/src/hooks/useMyPageQueries.ts
@@ -9,6 +9,7 @@ import {
import { UpdateProfileRequest } from '@/types/mypageTypes';
import useMyPageStore from '@/stores/MyPage/useMyPageStore';
import { useEffect } from 'react';
+import useUserStore from '@/stores/authStore';
export const QUERY_KEYS = {
PROFILE: ['mypage', 'profile'] as const,
@@ -47,6 +48,7 @@ export const useMyProfile = () => {
export const useUpdateProfile = () => {
const queryClient = useQueryClient();
const { setUser, setLoading, setError } = useMyPageStore();
+ const setGlobalUser = useUserStore((state) => state.setUser); // 헤더 상태 갱신 함수
const mutation = useMutation({
mutationFn: (data: UpdateProfileRequest) => updateMyProfile(data),
@@ -81,6 +83,7 @@ export const useUpdateProfile = () => {
setUser,
setLoading,
setError,
+ setGlobalUser, // [추가] 헤더 상태(authStore)도 동기화
]);
return mutation;
@@ -91,6 +94,8 @@ export const useUploadProfileImage = () => {
const queryClient = useQueryClient();
const { setUser, setLoading, setError } = useMyPageStore();
+ const setGlobalUser = useUserStore((state) => state.setUser); // 헤더 상태 갱신 함수
+
const mutation = useMutation({
mutationFn: async (file: File) => {
// 이미지 업로드
@@ -121,6 +126,11 @@ export const useUploadProfileImage = () => {
setUser(updatedUser);
queryClient.setQueryData(QUERY_KEYS.PROFILE, updatedUser);
+ setLoading(false);
+ setGlobalUser(updatedUser); // [추가] 헤더 상태(authStore)도 동기화
+
+ queryClient.setQueryData(QUERY_KEYS.PROFILE, updatedUser);
+
setLoading(false);
alert('프로필 이미지가 성공적으로 업로드되었습니다!');
}
@@ -138,6 +148,7 @@ export const useUploadProfileImage = () => {
mutation.error,
queryClient,
setUser,
+ setGlobalUser, // [추가] 의존성에 포함
setLoading,
setError,
]);
diff --git a/src/middleware.ts b/src/middleware.ts
index f34fe26..6dab8a9 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -4,6 +4,8 @@ import { NextRequest, NextResponse } from 'next/server';
* Next.js Middleware 함수로, 인증 상태에 따라 사용자의 접근을 제어합니다.
*
* - 로그인/회원가입 페이지에 접근 시 이미 accessToken 또는 refreshToken이 존재하면 메인 페이지로 리디렉트
+ * 👉 이 조건은 accessToken이 있다고 무조건 로그인 상태로 판단되어 버튼 클릭이 막히는 문제가 있어 제거 또는 완화함
+ *
* - 보호된 페이지(`/mypage` 하위) 접근 시 토큰이 모두 없으면 로그인 페이지로 리디렉트
* - 그 외에는 요청을 그대로 통과시킴
*
@@ -16,13 +18,10 @@ export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
- // 로그인/회원가입 페이지 접근 시 이미 로그인 상태면 메인으로 리디렉트
- if (
- (pathname === '/login' || pathname === '/signup') &&
- (accessToken || refreshToken)
- ) {
- return NextResponse.redirect(new URL('/', request.url));
- }
+ // 기존 코드에서 로그인/회원가입 접근 차단 조건 제거
+ // 이유: accessToken이 있어도 user 상태는 아직 하이드레이션 전일 수 있어서,
+ // 버튼이 보이지만 클릭 시 리다이렉트되어 이동이 안 되는 현상이 발생함
+ // 따라서 로그인 여부 판단은 클라이언트에서 하고, middleware는 보호 경로만 책임지도록 수정
// 보호 경로 설정 및 검사
const protectedPaths = ['/mypage'];