Skip to content

fix: ProtectedRoute에서 인증 상태 초기화 로직 추가#44

Merged
koreahghg merged 5 commits intomainfrom
fix/main
Dec 29, 2025
Merged

fix: ProtectedRoute에서 인증 상태 초기화 로직 추가#44
koreahghg merged 5 commits intomainfrom
fix/main

Conversation

@koreahghg
Copy link
Collaborator

💡 배경 및 개요

PR을 하게 된 문제상황, 배경 및 개요에 대해서 작성해주세요!

퍼블리싱의 경우 스크린샷/동영상도 추가해주면 좋아요!

Resolves: #{이슈번호}

📃 작업내용

PR에서 한 작업을 작성해주세요!

🙋‍♂️ 리뷰노트

구현 시에 고민이었던 점들 혹은 특정 부분에 대한 의도가 있었다면 PR 리뷰의 이해를 돕기 위해 서술해주세요!

또한 리뷰어에게 특정 부분에 대한 집중 혹은 코멘트 혹은 질문을 요청하는 경우에 작성하면 좋아요!

e.g. 작업을 끝내야할 시간이 얼마 없어 확장성보다는 동작을 위주로 만들었어요! 감안하고 리뷰해주세요!

✅ PR 체크리스트

템플릿 체크리스트 말고도 추가적으로 필요한 체크리스트는 추가해주세요!

  • 이 작업으로 인해 변경이 필요한 문서가 변경되었나요? (e.g. .env, 노션, README)
  • 이 작업을 하고나서 공유해야할 팀원들에게 공유되었나요? (e.g. "API 개발 완료됐어요", "환경값 추가되었어요")
  • 작업한 코드가 정상적으로 동작하나요?
  • Merge 대상 브랜치가 올바른가요?
  • PR과 관련 없는 작업이 있지는 않나요?

🎸 기타

@vercel
Copy link

vercel bot commented Dec 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
cklob-gami Ready Ready Preview, Comment Dec 29, 2025 5:38am

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @koreahghg, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 애플리케이션의 인증 흐름을 개선하여 ProtectedRoute 컴포넌트가 사용자의 인증 상태를 정확하게 판단하기 전에 불필요하게 리다이렉션되는 문제를 해결합니다. AuthContext에 'initialized' 플래그를 도입하고, 이 플래그가 true가 될 때까지 ProtectedRoute가 렌더링을 지연함으로써, 초기 로딩 시 발생할 수 있는 사용자 경험 저하를 방지합니다.

Highlights

  • 인증 상태 초기화 로직 추가: ProtectedRoute 컴포넌트가 인증 상태가 완전히 초기화될 때까지 기다리도록 변경되었습니다.
  • AuthContext에 초기화 상태 도입: AuthContext에 'initialized' 상태를 추가하여 인증 상태의 로딩 완료 여부를 추적합니다.
  • 불필요한 리다이렉션 방지: 인증 상태가 초기화되는 동안 ProtectedRoute가 null을 반환하여 사용자가 로그인 상태를 확인하기 전에 잘못 리다이렉션되는 것을 방지합니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이 PR은 ProtectedRoute에서 발생할 수 있는 경쟁 상태를 방지하기 위해 인증 상태 초기화를 처리하는 initialized 플래그를 도입했습니다. 이 패턴은 특히 향후 비동기 인증 확인을 위해 견고한 방법입니다. 하지만 localStorage를 사용하는 현재의 동기적 구현에서는 약간의 복잡성과 사소한 UI 깜빡임을 추가합니다. 제 리뷰에는 기존의 동기적 초기화가 이미 안전하므로, 현재로서는 initialized 플래그를 제거하여 이를 단순화하자는 제안이 포함되어 있습니다. 코드는 구조가 잘 짜여 있고 의도가 명확합니다.

Comment on lines +15 to +17
const { isAuthenticated, user, initialized } = useAuth();
// while auth state is initializing, don't redirect — avoid false negatives
if (!initialized) return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

인증 상태가 비동기적으로 초기화될 때를 대비한 initialized 플래그는 좋은 패턴입니다. 하지만 현재 AuthContext에서는 useState의 지연 초기화(lazy initializer)를 통해 동기적으로 상태를 설정하고 있어 첫 렌더링부터 isAuthenticated 값이 정확합니다.

현재 이 if (!initialized) 확인 로직은 불필요하며, 인증된 사용자가 페이지를 새로고침할 때마다 잠시 빈 화면을 보여주게 되어 사용자 경험을 저해할 수 있습니다.

따라서 AuthContextProtectedRoute 양쪽에서 initialized 관련 로직을 모두 제거하여 코드를 단순화하고 사용자 경험을 개선하는 것을 제안합니다. 나중에 비동기 인증 로직이 추가될 때 이 패턴을 다시 도입하는 것이 좋겠습니다.

Suggested change
const { isAuthenticated, user, initialized } = useAuth();
// while auth state is initializing, don't redirect — avoid false negatives
if (!initialized) return null;
const { isAuthenticated, user } = useAuth();

Comment on lines +57 to +59
useEffect(() => {
setInitialized(true);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ProtectedRoute.tsx 파일에 남긴 피드백에 이어, 현재 동기적인 인증 방식에서는 이 useEffect가 불필요합니다. 이 훅과 함께 AuthContext 내 다른 initialized 관련 코드들(state, context value, type)도 함께 제거하는 것을 권장합니다.

@koreahghg koreahghg merged commit 3833da1 into main Dec 29, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants