[#48] Feat/48/소셜로그인기능 - #49
Merged
Hidden character warning
The head ref may contain hidden characters: "Feat/48/\uc18c\uc15c\ub85c\uadf8\uc778\uae30\ub2a5"
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
❓이슈
📝 Description
Google 및 Kakao 소셜 로그인 기능을 구현합니다.
기존 NextAuth 내장 Provider 방식 대신, OAuth 2.0 인가코드를 백엔드에 전달하는 커스텀 플로우로 구현했습니다.
기존 이메일 로그인과 동일한 세션 구조(
accessToken,userId,picture)를 유지합니다.추가로 마이페이지에서 프로필 이미지가 없을 때 빈 원으로 표시되던 문제를 함께 수정합니다.
구현 흐름
로그인 버튼 클릭
│
▼
state 생성 (CSRF 방지) → sessionStorage 저장
│
▼
Google/Kakao OAuth 인가 URL로 window.location.href 리다이렉트
│
▼ (사용자 소셜 계정 인증 완료)
/oauth/google 또는 /oauth/kakao 콜백 페이지 진입
│
├─ URL의 state와 sessionStorage의 state 비교 검증
├─ 백엔드 POST /api/v1/auth/social/login/{provider} 호출
│ body: { state, redirectUri, token(인가코드) }
├─ 응답에서 accessToken, user 정보 수신
│
▼
signIn('social', { accessToken, userId, email, name, picture })
│
▼
NextAuth JWT 세션 생성 → /workspace 이동
변경 파일 상세
lib/auth-api.tssocialLoginApi(provider, body)함수 추가SocialLoginRequest,SocialAuthResponse타입 추가types/next-auth.d.tsJWT인터페이스에picture?: string | null필드 추가app/api/auth/[...nextauth]/route.ts'credentials'로 명시'social'id CredentialsProvider 추가 — 콜백 페이지에서 전달받은accessToken을 그대로 JWT 세션으로 저장jwt콜백에서picture필드 저장 추가app/oauth/google/page.tsx(신규)useRef가드로 React Strict Mode 이중 실행 방지state검증(CSRF) →socialLoginApi('google', ...)→signIn('social', ...)→/workspace이동/login으로 이동app/oauth/kakao/page.tsx(신규)app/(before-login)/(auth)/login/page.tsxonClick을signIn('google/kakao')→handleGoogleLogin()/handleKakaoLogin()으로 교체state생성 후sessionStorage저장, OAuth 인가 URL로 리다이렉트middleware.tsoauth제외 추가/((?!api|_next/static|_next/image|favicon.ico).*)/((?!api|_next/static|_next/image|favicon.ico|oauth).*)/oauth/google,/oauth/kakao콜백 페이지가 미들웨어 로그인 리다이렉트에 차단되지 않도록 처리next.config.tsimages.remotePatterns에lh3.googleusercontent.com추가app/(after-login)/mypage/page.tsxbg-blue-100배경에 이름 첫 글자 표시🌀 PR Type
어떤 변경 사항이 있나요?
✅ Checklist
PR Checklist
PR이 다음 요구 사항을 충족하는지 확인하세요.
Test Checklist