Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/api/user/me/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export async function DELETE() {
await prisma.$transaction([
prisma.user.update({
where: { id: userId },
data: { deletedAt: now, deletionRequestedAt: now },
data: { deletedAt: now, deletionRequestedAt: now, kakaoId: null },
}),
prisma.account.deleteMany({
where: { userId },
}),
Comment on lines +305 to 309

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.

prisma.auditLog.create({
data: {
Expand Down