fix(auth): 탈퇴 회원 동일 카카오 계정 재가입 허용 - #94
Conversation
탈퇴 처리 시 accounts 레코드 삭제 및 kakao_id null 처리를 추가하여 탈퇴 후 동일 카카오 계정으로 재가입이 가능하도록 수정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthrough
Changes계정 삭제 시 Kakao 연동 해제
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/api/user/me/route.ts`:
- Around line 305-309: The re-signup flow has two blocking issues that prevent
deleted users from creating a new account. First, in the signIn callback around
line 130-132, there is a check that returns false if the existing user has a
deletedAt value, which prevents authentication before reaching the new User
creation logic. Second, when deleting a user in the code around lines 305-309,
only kakaoId is set to null while email remains unchanged, so when the same
email comes back from Kakao during re-signup, it violates the email `@unique`
constraint and fails to create a new User. To fix this, either set the email
field to null alongside kakaoId in the deletion logic, or modify the signIn
callback to not block deleted users so they can proceed to the new User creation
flow, depending on your architectural preference.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 45fddf13-ff9b-4846-8b8e-e229d65b4a90
📒 Files selected for processing (1)
src/app/api/user/me/route.ts
| data: { deletedAt: now, deletionRequestedAt: now, kakaoId: null }, | ||
| }), | ||
| prisma.account.deleteMany({ | ||
| where: { userId }, | ||
| }), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# NextAuth 어댑터 설정 및 signIn 콜백에서 deletedAt 처리 로직 확인
# NextAuth 설정 파일 찾기
echo "=== NextAuth configuration files ==="
fd -e ts -e tsx "auth" --type f | head -20
# signIn 콜백에서 deletedAt 관련 로직 확인
echo -e "\n=== signIn callback and deletedAt handling ==="
rg -n "signIn.*callback|deletedAt" --type ts -C 3
# User 생성 또는 업데이트 시 email 처리 확인
echo -e "\n=== User creation/update with email handling ==="
rg -n "createUser|saveFirstLoginFields" --type ts -C 5Repository: I5-Project/TALKY-OWL
Length of output: 13685
🏁 Script executed:
# 삭제된 사용자 재가입 관련 로직 확인
rg -n "deletedAt.*false|deleted.*user.*recre" --type ts -C 5
# NextAuth의 signIn 콜백 전체 플로우 확인
cat src/lib/auth/index.ts | head -200Repository: I5-Project/TALKY-OWL
Length of output: 5317
재가입 흐름에서 두 가지 critical issue가 있습니다.
- signIn 콜백이 삭제된 사용자를 차단함 (line 130-132)
if (existing?.deletedAt) {
return false // 재가입 불가능
}
PR 목표인 "새로운 User 생성"과 모순됩니다. 삭제된 사용자가 동일 카카오 계정으로 다시 로그인하면 signIn이 false를 반환해 인증이 차단되므로, 새 User 생성 로직에 도달하지 못합니다.
- 이메일 고유 제약조건이 새 User 생성을 차단할 수 있음
삭제 시kakaoId: null만 처리하고 email은 유지됩니다(line 305-309). 재가입 시 카카오에서 동일 이메일을 제공하면email@unique`` 제약조건 위반으로 새 User 생성 실패합니다.
필요한 수정:
- 삭제 시 email도 함께 null로 처리하거나
- signIn 콜백을 수정해 삭제된 사용자도 새 User로 재가입할 수 있도록 하거나
- NextAuth 어댑터 커스터마이징으로 soft-deleted 사용자를 다르게 처리
현재 구현은 재가입 기능을 완전히 지원하지 못합니다.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/app/api/user/me/route.ts` around lines 305 - 309, The re-signup flow has
two blocking issues that prevent deleted users from creating a new account.
First, in the signIn callback around line 130-132, there is a check that returns
false if the existing user has a deletedAt value, which prevents authentication
before reaching the new User creation logic. Second, when deleting a user in the
code around lines 305-309, only kakaoId is set to null while email remains
unchanged, so when the same email comes back from Kakao during re-signup, it
violates the email `@unique` constraint and fails to create a new User. To fix
this, either set the email field to null alongside kakaoId in the deletion
logic, or modify the signIn callback to not block deleted users so they can
proceed to the new User creation flow, depending on your architectural
preference.
Summary
accounts테이블 레코드 삭제 추가 (account.deleteMany)users.kakao_idnull 처리 추가기존에는 탈퇴 시
users.deleted_at만 설정하고accounts레코드가 남아있어, 동일 카카오 계정으로 재로그인 시 NextAuth가 탈퇴된 기존 유저로 인식 →signIncallback에서deletedAt감지 → 로그인 차단되는 문제가 있었습니다.변경 후 재가입 흐름:
accounts레코드 삭제 → NextAuth가 해당 카카오 계정을 신규로 인식createUser이벤트 →saveFirstLoginFields호출 → 정상 신규 가입 처리Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
버그 수정