저는 본인인증 DI가 같은 계정이 여러 개 생기는 문제를 겪었습니다. 사용자에게 “이미 인증한 계정이 있어요”라고 안내하고 싶었지만, RLS 때문에 클라이언트가 마음대로 프로필을 조회할 수 없었죠. 그래서 서비스 롤 클라이언트를 이용해 중복 계정을 탐지하는 API를 만들었습니다.
쿼리에 di가 없으면 세션 사용자 프로필을 조회해 DI를 찾습니다. 둘 다 없으면 400으로 종료합니다.
프로필 테이블에서 동일한 DI를 가진 항목을 모두 가져옵니다. 필요한 필드는 이름, 전화번호, 인증 여부 등입니다.
각 프로필 ID로 admin.auth.admin.getUserById를 호출해 활성/비활성 상태를 확인합니다. 현재 사용자와 동일하면 otherUsers에서 제외합니다.
import { createAdminClient } from './supabaseAdmin';
const adminClient = createAdminClient();
const { data: profiles } = await adminClient
.from('profile')
.select('id, di, full_name, phone_number, is_verified, is_complete')
.eq('di', di);
const users = await Promise.all(
(profiles ?? []).map(async profile => {
const { data } = await adminClient.auth.admin.getUserById(profile.id);
return data?.user ?? null;
}),
);
const otherUsers = users.filter(
user => user && (!currentUserId || user.id !== currentUserId),
);
return {
success: true,
di,
profiles,
users,
otherUsers,
isDuplicated: otherUsers.length > 0,
};
isDuplicated 플래그와 otherUsers 배열을 포함해 반환했습니다.이제는 DI가 중복된 사용자가 있으면 UI에서 즉시 알려줄 수 있습니다. 계정 복구나 고객센터 응대도 훨씬 빨라졌죠. 다음에는 중복 계정을 자동으로 잠그는 정책을 검토해볼 생각입니다.
여러분은 본인인증 식별자를 어떻게 관리하고 계신가요? 다른 사례가 있다면 댓글로 공유해주세요.