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

+45 -2
View File
@@ -1,4 +1,5 @@
import { meQueryKey, updateMeMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { clearTokens } from '@nalssigak/shared/api/auth';
import { meQueryKey, updateMeMutation, withdrawMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { AVATAR_COLORS, CHARACTERS, MOODS } from '@nalssigak/shared/lib';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
@@ -9,7 +10,48 @@ import { useAuth } from '@/lib/auth';
import { Body, Field, useSoft } from './parts';
/** 내 정보: 캐릭터·배경색·기분·닉네임·로그아웃 */
/** 탈퇴: 한 번 더 묻고 지운다. 계정이 없어지니 이 기기 토큰도 지운다 */
function Withdraw({ onDone }: { onDone: () => void }) {
const withdraw = useMutation(withdrawMutation());
const [asking, setAsking] = useState(false);
const [failed, setFailed] = useState(false);
if (!asking)
return (
<Pressable onPress={() => setAsking(true)} hitSlop={8} className="self-center p-1">
<Text className="text-[13px] font-semibold text-ink3">탈퇴하기</Text>
</Pressable>
);
const run = () => {
setFailed(false);
withdraw.mutate(
{},
{
onSuccess: (res) => {
if (!res.result?.success) return setFailed(true);
clearTokens();
onDone();
},
onError: () => setFailed(true),
},
);
};
return (
<View className="gap-2.5 rounded-[18px] p-3.5" style={{ backgroundColor: 'rgb(255 59 92 / 0.08)' }} accessibilityRole="alert">
<Text className="text-center text-sm font-bold text-ink">{'탈퇴하면 계정과 남긴 댓글·좋아요가\n모두 지워져요. 되돌릴 수 없어요.'}</Text>
<View className="flex-row gap-2">
<Pressable onPress={() => setAsking(false)} disabled={withdraw.isPending} className="flex-1 rounded-[14px] bg-card p-3">
<Text className="text-center text-sm font-extrabold text-ink">그만둘게요</Text>
</Pressable>
<Pressable onPress={run} disabled={withdraw.isPending} className="flex-1 rounded-[14px] bg-heart p-3 disabled:opacity-60">
<Text className="text-center text-sm font-extrabold text-white">탈퇴할게요</Text>
</Pressable>
</View>
{failed && <Text className="text-center text-[13px] font-bold text-heart">탈퇴하지 못했어요. 잠시 뒤에 다시 해 주세요.</Text>}
</View>
);
}
/** 내 정보: 캐릭터·배경색·기분·닉네임·로그아웃·탈퇴 */
export function MeSheet({ onDone }: { onDone: () => void }) {
const { me, logout } = useAuth();
const s = useSoft();
@@ -123,6 +165,7 @@ export function MeSheet({ onDone }: { onDone: () => void }) {
>
<Text className="text-center text-[15px] font-extrabold text-ink">로그아웃</Text>
</Pressable>
<Withdraw onDone={onDone} />
</Body>
);
}
+11 -2
View File
@@ -1,5 +1,5 @@
import { clearTokens, getAccessToken, subscribeAuth } from '@nalssigak/shared/api/auth';
import { meOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { meOptions, meQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { logout as logoutOnServer } from '@nalssigak/shared/api/client/sdk.gen';
import type { Me } from '@nalssigak/shared/api/client/types.gen';
import { useQuery, useQueryClient } from '@tanstack/react-query';
@@ -29,7 +29,16 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const me = useQuery({ ...meOptions(), enabled: !!token });
// 로그인·로그아웃하면 좋아요 여부가 달라지니 받아 둔 데이터를 다시 받는다
useEffect(() => subscribeAuth((reason) => reason === 'change' && queryClient.invalidateQueries()), [queryClient]);
// 로그아웃·탈퇴 땐 내 정보 캐시를 먼저 버린다. 남겨 두면 다시 받다가 401 이 나서 로그인 창이 뜬다
useEffect(
() =>
subscribeAuth((reason) => {
if (reason !== 'change') return;
if (!getAccessToken()) queryClient.removeQueries({ queryKey: meQueryKey() });
void queryClient.invalidateQueries();
}),
[queryClient],
);
const mePending = !!token && me.isPending;
const api = useMemo(() => ({ loggedIn: !!token, me: (token && me.data?.me) || null, mePending, logout }), [token, me.data, mePending]);