Skip to content

fix(auth): 탈퇴 회원 동일 카카오 계정 재가입 허용 - #94

Merged
evenif99 merged 1 commit into
devfrom
fix/withdraw-reregister
Jun 20, 2026
Merged

fix(auth): 탈퇴 회원 동일 카카오 계정 재가입 허용#94
evenif99 merged 1 commit into
devfrom
fix/withdraw-reregister

Conversation

@evenif99

@evenif99 evenif99 commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • 탈퇴 처리 시 accounts 테이블 레코드 삭제 추가 (account.deleteMany)
  • 탈퇴 처리 시 users.kakao_id null 처리 추가

기존에는 탈퇴 시 users.deleted_at만 설정하고 accounts 레코드가 남아있어, 동일 카카오 계정으로 재로그인 시 NextAuth가 탈퇴된 기존 유저로 인식 → signIn callback에서 deletedAt 감지 → 로그인 차단되는 문제가 있었습니다.

변경 후 재가입 흐름:

  1. accounts 레코드 삭제 → NextAuth가 해당 카카오 계정을 신규로 인식
  2. 신규 User 생성 → createUser 이벤트 → saveFirstLoginFields 호출 → 정상 신규 가입 처리

Test plan

  • 카카오 로그인 후 회원탈퇴
  • 동일 카카오 계정으로 재로그인 시 신규 가입 플로우 진입 확인 (약관 동의 페이지)
  • 재가입 후 서비스 정상 이용 확인

🤖 Generated with Claude Code

Summary by CodeRabbit

버그 수정

  • 사용자 계정 삭제 시 Kakao 연동 식별자도 함께 안전하게 해제되도록 개선되었습니다.

탈퇴 처리 시 accounts 레코드 삭제 및 kakao_id null 처리를 추가하여
탈퇴 후 동일 카카오 계정으로 재가입이 가능하도록 수정

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
talky-owl Ready Ready Preview, Comment Jun 20, 2026 9:27am

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DELETE /api/user/me 엔드포인트의 삭제 트랜잭션에서 prisma.user.update 데이터에 kakaoId: null이 추가되었습니다. 계정 삭제 시 deletedAt, deletionRequestedAt과 함께 Kakao 연동 식별자도 함께 초기화됩니다.

Changes

계정 삭제 시 Kakao 연동 해제

Layer / File(s) Summary
삭제 트랜잭션 kakaoId null 처리
src/app/api/user/me/route.ts
prisma.user.update 호출 데이터에 kakaoId: null이 추가되어, 계정 삭제 트랜잭션 실행 시 Kakao 연동 식별자가 함께 해제됩니다.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • lyla-bae
  • wjdalss21

Poem

🐇 탈탈탈, 카카오 연결도 끊어지네,
계정 삭제 시 null로 깔끔하게,
deletedAt도, kakaoId도 훌훌~
토끼가 코드를 정리하니 기분 좋아,
다음 로그인엔 새 출발이라네! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive 설명이 대체로 완성되어 있으나, 제공된 템플릿의 필수 섹션 중 일부가 누락되거나 미완성되어 있습니다. 템플릿의 필수 섹션(담당 작업 영역, 관련 Issue, 변경 사항, 테스트 결과, 작업 범위 확인, 보안/개인정보 확인, DB/API/Storage 변경 여부)을 완성하시기 바랍니다.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 주요 변경사항을 명확하게 설명하고 있으며, 탈퇴 회원의 동일 카카오 계정 재가입 허용이라는 핵심 기능을 정확하게 전달합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/withdraw-reregister

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between c61d04e and 2dbfa3e.

📒 Files selected for processing (1)
  • src/app/api/user/me/route.ts

Comment on lines +305 to 309
data: { deletedAt: now, deletionRequestedAt: now, kakaoId: null },
}),
prisma.account.deleteMany({
where: { userId },
}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 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 5

Repository: 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 -200

Repository: I5-Project/TALKY-OWL

Length of output: 5317


재가입 흐름에서 두 가지 critical issue가 있습니다.

  1. signIn 콜백이 삭제된 사용자를 차단함 (line 130-132)
if (existing?.deletedAt) {
  return false  // 재가입 불가능
}

PR 목표인 "새로운 User 생성"과 모순됩니다. 삭제된 사용자가 동일 카카오 계정으로 다시 로그인하면 signIn이 false를 반환해 인증이 차단되므로, 새 User 생성 로직에 도달하지 못합니다.

  1. 이메일 고유 제약조건이 새 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.

@evenif99 evenif99 self-assigned this Jun 20, 2026
@evenif99
evenif99 merged commit bed7aab into dev Jun 20, 2026
3 checks passed
@evenif99
evenif99 deleted the fix/withdraw-reregister branch June 25, 2026 04:13
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.

1 participant