feat: 회원 탈퇴 (DELETE /v1/auth/me, 웹·앱 내 정보 시트 '탈퇴하기')

- 계정과 남긴 댓글·좋아요·저장을 한 트랜잭션으로 지우고 게시물·댓글 수를 맞춘다
- 로그아웃·탈퇴 때 내 정보 캐시를 먼저 버려 401 로 로그인 창이 뜨지 않게
- 탈퇴 테스트 추가, 공용 API 클라이언트 다시 생성
This commit is contained in:
minaChoi committed 2026-10-19 11:33:05 +09:00
1 parent dd2d02758b
commit 86a0ea26ca
15 files changed
+313 -17

No files matched your search

+49 -2
View File
@@ -1,6 +1,6 @@
import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteData } from '@tanstack/react-query'
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState, type FormEvent, type ReactNode } from 'react'
import { setTokens, subscribeAuth } from '@nalssigak/shared/api/auth'
import { clearTokens, setTokens, subscribeAuth } from '@nalssigak/shared/api/auth'
import { SITE_URL } from '../api/setup'
import {
addCommentMutation,
@@ -18,6 +18,7 @@ import {
signupMutation,
unlikeCommentMutation,
updateMeMutation,
withdrawMutation,
} from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
import type { CommentData, Factor, ResAuth, ResCommentList, ResIndexDetail } from '@nalssigak/shared/api/client/types.gen'
import { track } from '../lib/analytics'
@@ -862,7 +863,52 @@ function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: ()
)
}
/* ---------- 내 정보: 캐릭터·닉네임·로그아웃 ---------- */
/* ---------- 내 정보: 캐릭터·닉네임·로그아웃·탈퇴 ---------- */
/** 탈퇴: 한 번 더 묻고 지운다. 계정이 없어지니 이 기기 토큰도 지운다 */
function Withdraw({ onDone }: { onDone: () => void }) {
const withdraw = useMutation(withdrawMutation())
const [asking, setAsking] = useState(false)
const [failed, setFailed] = useState(false)
if (!asking)
return (
<button type="button" onClick={() => setAsking(true)} className="cursor-pointer self-center p-1 text-[13px] font-semibold text-(--ink3)">
탈퇴하기
</button>
)
const run = () => {
setFailed(false)
withdraw.mutate(
{},
{
onSuccess: (res) => {
if (!res.result?.success) return setFailed(true)
clearTokens()
onDone()
},
onError: () => setFailed(true),
},
)
}
return (
<div className="flex flex-col gap-2.5 rounded-[18px] bg-[#fff1f3] p-3.5" role="alert">
<p className="m-0 text-center text-sm font-bold text-(--ink)">
탈퇴하면 계정과 남긴 댓글·좋아요가
<br />
모두 지워져요. 되돌릴 수 없어요.
</p>
<div className="flex gap-2">
<button type="button" onClick={() => setAsking(false)} disabled={withdraw.isPending} className="flex-1 cursor-pointer rounded-[14px] bg-white p-3 text-sm font-extrabold text-(--ink)">
그만둘게요
</button>
<button type="button" onClick={run} disabled={withdraw.isPending} className="flex-1 cursor-pointer rounded-[14px] bg-(--heart) p-3 text-sm font-extrabold text-white disabled:opacity-60">
탈퇴할게요
</button>
</div>
{failed && <p className="m-0 text-center text-[13px] font-bold text-(--heart)">탈퇴하지 못했어요. 잠시 뒤에 다시 해 주세요.</p>}
</div>
)
}
function MeSheet({ onDone }: { onDone: () => void }) {
const { me, logout } = useAuth()
const queryClient = useQueryClient()
@@ -981,6 +1027,7 @@ function MeSheet({ onDone }: { onDone: () => void }) {
>
로그아웃
</button>
<Withdraw onDone={onDone} />
</Body>
)
}