-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: 토큰 인증 시스템의 엣지 케이스 해결 및 레거시 코드 정리 #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e1a093d
f9ba4b6
92ee10b
3d0e1df
82504f5
11d56e2
8896999
94c5f4c
977dca0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 'use client'; | ||
|
|
||
| import { useRouter } from 'next/navigation'; | ||
| import { Button } from '@/components/buttons/Button'; | ||
| import { useAuth } from '@/hooks/useAuth'; | ||
|
|
||
| interface StartButtonProps { | ||
| className?: string; | ||
| children: React.ReactNode; | ||
| } | ||
| export default function StartButton({ | ||
| className, | ||
| children, | ||
| }: StartButtonProps) { | ||
| const router = useRouter(); | ||
| const { isAuth, isLoading } = useAuth(); | ||
|
|
||
| const handleStart = () => { | ||
| router.replace(isAuth ? '/main' : '/login'); | ||
| }; | ||
| return ( | ||
| <Button | ||
| className={className} | ||
| onClick={handleStart} | ||
| disabled={isLoading} | ||
| size="lg" | ||
| > | ||
| {children} | ||
| </Button> | ||
| ); | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -95,7 +95,7 @@ export const Button = React.forwardRef< | |||||
| const isDisabled = disabled; | ||||||
|
|
||||||
| const classes = cn( | ||||||
| 'relative inline-flex items-center justify-center rounded-lg font-medium select-none overflow-hidden', | ||||||
| 'relative flex items-center justify-center rounded-lg font-medium select-none overflow-hidden', | ||||||
|
||||||
| 'relative flex items-center justify-center rounded-lg font-medium select-none overflow-hidden', | |
| 'relative inline-flex items-center justify-center rounded-lg font-medium select-none overflow-hidden', |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,14 @@ const PUBLIC_ROUTES = ['/login', '/signup']; | |||||||||||||
|
|
||||||||||||||
| const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Set-Cookie 헤더를 현재 환경에 맞게 수정 | ||||||||||||||
| * - Domain 속성 제거 (현재 도메인으로 자동 설정) | ||||||||||||||
| */ | ||||||||||||||
| function modifySetCookie(cookie: string): string { | ||||||||||||||
| return cookie.replace(/Domain=[^;]+;?\s*/gi, ''); | ||||||||||||||
|
||||||||||||||
| return cookie.replace(/Domain=[^;]+;?\s*/gi, ''); | |
| // 중간/끝에 위치한 Domain 속성 제거 | |
| let result = cookie.replace(/;\s*Domain=[^;]+/gi, ''); | |
| // 맨 앞에 위치한 Domain 속성 제거 | |
| result = result.replace(/^Domain=[^;]+;?\s*/i, ''); | |
| return result; |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
쿠키를 수동으로 구성할 때 refreshToken 값에 대한 URL 인코딩이 누락되어 있습니다. 토큰 값에 특수 문자가 포함된 경우 파싱 오류가 발생할 수 있습니다.
제안:
Cookie: `refreshToken=${encodeURIComponent(refreshToken)}`,| Cookie: `refreshToken=${refreshToken}`, | |
| Cookie: `refreshToken=${encodeURIComponent(refreshToken)}`, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,14 +35,21 @@ export async function AuthHydrationProvider({ | |
| await queryClient.prefetchQuery({ | ||
| queryKey: getGetCurrentUserQueryKey(), | ||
| queryFn: () => getServerCurrentUser(), | ||
| staleTime: 13 * 60 * 1000, // 13분 | ||
| staleTime: (query) => { | ||
| if ( | ||
| query.state.status === 'error' || | ||
| query.state.data === null | ||
| ) { | ||
| return 0; | ||
| } | ||
| return 13 * 60 * 1000; // 13분 | ||
| }, | ||
|
Comment on lines
+38
to
+46
|
||
| }); | ||
| } else { | ||
| // 토큰이 없으면 비로그인 상태로 초기화 | ||
| queryClient.setQueryData(getGetCurrentUserQueryKey(), null); | ||
| } | ||
| } | ||
| // HTTP 모드에서는 아무것도 하지 않음 (CSR이 알아서 처리) | ||
|
|
||
| return ( | ||
| <HydrationBoundary state={dehydrate(queryClient)}> | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logout()호출 직후router.push('/')를 실행하면 로그아웃 API 요청이 완료되기 전에 페이지 이동이 발생할 수 있습니다. 이는 비동기 작업이므로 완료를 기다려야 합니다.문제점:
logout()은mutate함수로 비동기 작업을 시작만 함router.push('/')가 실행되어 페이지 이동제안:
또는
useLogout훅의onSuccess콜백에서 리다이렉트를 처리하는 방법도 있습니다.