-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.ts
More file actions
33 lines (29 loc) · 1.23 KB
/
Copy pathdelete.ts
File metadata and controls
33 lines (29 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { onCall, HttpsError } from "firebase-functions/v2/https";
import * as admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
export const deleteUserFirestoreData = onCall({
cors: true,
maxInstances: 10,
region: "asia-northeast3"
},
async (request) => {
if (!request.auth?.uid) {
logger.error("deleteUserFirestoreData called without authenticated uid", {
auth: request.auth ?? null
});
throw new HttpsError("unauthenticated", "로그인 필요");
}
const uid = request.auth.uid;
try {
const userDocRef = admin.firestore().doc(`users/${uid}`);
await admin.firestore().recursiveDelete(userDocRef);
// Firestore의 recursiveDelete API 사용 (firebase-tools v9.12.0+)
// 실제로는 admin SDK엔 없고, 아래처럼 functions에서 사용할 수 있음
// https://firebase.google.com/docs/firestore/solutions/delete-collections?hl=ko#cloud-functions
// @ts-ignore
return { success: true }
} catch (err: any) {
throw new HttpsError("internal", `삭제 중 오류: ${err.message || err}`);
}
}
);