Skip to content

소셜로그인 next-auth -> cookie 변경#117

Merged
leetaewon123 merged 6 commits intodevfrom
fix/auth
Sep 11, 2025
Merged

소셜로그인 next-auth -> cookie 변경#117
leetaewon123 merged 6 commits intodevfrom
fix/auth

Conversation

@leetaewon123
Copy link
Copy Markdown
Collaborator

@leetaewon123 leetaewon123 commented Sep 11, 2025

🔎 작업 사항

  • 소셜로그인 next-auth -> cookie 변경

➕ 관련 이슈

Summary by CodeRabbit

  • Bug Fixes

    • 로그인 실패 시 명확한 알림 제공 및 후속 처리 중단
    • 로그아웃 시 사용자 상태가 정상적으로 초기화됨
    • 요청 처리 중 민감 정보 로그 출력 제거
  • Refactor

    • 소셜 로그인 흐름을 토큰 기반으로 개선하고 사용자 정보 자동 로딩
    • 내비게이션 바가 토큰 대신 사용자 상태로 UI 표시 결정
  • Chores

    • 불필요한 디버그 로그 제거

@leetaewon123 leetaewon123 merged commit a75cc8c into dev Sep 11, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

여러 인증 흐름을 정비했습니다. 디버그 로그를 제거하고, 로그아웃 시 사용자 스토어를 초기화하도록 수정했으며, UserStore의 setUser가 null을 허용하도록 타입을 확장했습니다. 로그인/소셜로그인은 토큰 저장 후 유저 정보를 API로 조회해 스토어에 반영하고, 네비게이션 바는 사용자 존재 여부로 UI를 분기합니다.

Changes

Cohort / File(s) Summary
Logging cleanup
src/api/client/api.ts, src/api/interceptor/request.interceptor.ts
불필요한 console.log 제거(클라이언트 GET 헬퍼, 요청 인터셉터의 토큰 로그). 기능 로직 변경 없음.
Logout + user store sync
src/entities/auth/model/mutation/auth.mutation.ts
로그아웃 시 useUserStore의 setUser(null) 호출을 추가하여 클라이언트 사용자 상태 초기화.
User store type widening
src/entities/user/model/store.ts
UserState.setUser의 시그니처를 (IMyInfo) → (IMyInfo | null)로 확장하고 구현 반영.
Login hook: response/error handling
src/features/auth/hooks/useLogin.ts
200이 아닌 응답 시 경고 후 조기 종료 추가. 에러 처리 분기 개선(알림 메시지 분기). 성공 시 기존 토큰 설정 및 유저정보 조회 흐름 유지.
Social login flow overhaul
src/features/auth/hooks/useSocialLogin.ts
NextAuth signIn 제거. 쿠키에 토큰 저장 후 API로 유저정보 조회하여 setUser 실행. 성공 시 onLoginSuccess 또는 '/' 이동. 오류 처리 추가.
Navigation bar gating by user
src/widgets/NavigationBar/ui/AuthActions.tsx
쿠키 기반 accessToken 체크 제거. user 존재 여부로 메뉴/로그인 버튼 분기. 기존 UI 구조 유지.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant L as useLogin Hook
  participant API as Auth API
  participant S as User Store
  participant NAV as Router

  U->>L: submit(credentials)
  L->>API: POST /login
  API-->>L: status 200 + tokens / non-200
  alt status 200
    L->>L: save tokens (cookie/local)
    L->>API: GET /user-info
    API-->>L: 200 + IMyInfo / error
    alt user-info 200
      L->>S: setUser(user)
      L->>NAV: redirect '/' or onLoginSuccess()
    else user-info error
      L->>U: alert(error message)
    end
  else non-200
    L->>U: alert(server message or default)
  end
Loading
sequenceDiagram
  autonumber
  participant U as User (Social)
  participant SL as useSocialLogin Hook
  participant CK as Cookies
  participant API as User API
  participant S as User Store
  participant NAV as Router

  U->>SL: arrive with accessToken, refreshToken
  SL->>SL: guard missing tokens (exit)
  SL->>CK: set cookies (accessToken, refreshToken)
  SL->>API: GET /user-info
  API-->>SL: 200 + IMyInfo / error
  alt 200
    SL->>S: setUser(user)
    SL->>NAV: onLoginSuccess() or redirect '/'
  else error
    SL->>U: alert(fetch failed)
  end
Loading
sequenceDiagram
  autonumber
  participant U as User
  participant LG as logoutMutation
  participant TOK as TokenStore
  participant S as User Store
  participant NAV as Router
  participant QC as QueryCache

  U->>LG: logout()
  LG->>TOK: remove tokens
  LG->>S: setUser(null)
  LG->>QC: invalidate/clear caches
  LG->>NAV: navigate to '/'
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Fix/header #107: 동일 파일(useSocialLogin.ts, api.ts)을 편집하며 API 기반 유저정보 조회와 스토어 업데이트 흐름을 도입/수정.
  • Fix/header #106: useSocialLogin.ts와 AuthActions.tsx에서 로그인 후 사용자 정보 반영과 UI 분기 로직을 유사하게 변경.
  • refactoring : landing page #48: logout mutation에서 로그아웃 부가 동작을 확장하는 변경과 본 PR의 setUser(null) 동기화가 맞닿아 있음.

Suggested labels

refactoring

Suggested reviewers

  • grimza99

Poem

새 토큰 꽁꽁, 쿠키에 착!
유저정보 쏙쏙, 스토어에 낙.
로그는 가볍게 털털—사라졌지 락.
바엔 토큰 말고 유저로 딱!
로그아웃이면 퐁—null로 착.
(∩`-´)⊃━☆゚.*. 깔끔한 흐름, 토끼도 박수짝!


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26c22bf and 084dc13.

📒 Files selected for processing (7)
  • src/api/client/api.ts (0 hunks)
  • src/api/interceptor/request.interceptor.ts (2 hunks)
  • src/entities/auth/model/mutation/auth.mutation.ts (3 hunks)
  • src/entities/user/model/store.ts (1 hunks)
  • src/features/auth/hooks/useLogin.ts (2 hunks)
  • src/features/auth/hooks/useSocialLogin.ts (2 hunks)
  • src/widgets/NavigationBar/ui/AuthActions.tsx (1 hunks)
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/auth

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot mentioned this pull request Oct 7, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Oct 26, 2025
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant