|
1 | | -import { onCall, HttpsError } from "firebase-functions/v2/https"; |
| 1 | +import * as functions from "firebase-functions/v1"; |
2 | 2 | import * as admin from "firebase-admin"; |
3 | 3 | import * as logger from "firebase-functions/logger"; |
4 | 4 |
|
5 | | -export const deleteUserFirestoreData = onCall({ |
6 | | - cors: true, |
7 | | - maxInstances: 10, |
8 | | - region: "asia-northeast3" |
9 | | - }, |
10 | | - async (request) => { |
11 | | - if (!request.auth?.uid) { |
12 | | - logger.error("deleteUserFirestoreData called without authenticated uid", { |
13 | | - auth: request.auth ?? null |
14 | | - }); |
15 | | - throw new HttpsError("unauthenticated", "로그인 필요"); |
16 | | - } |
17 | | - |
18 | | - const uid = request.auth.uid; |
| 5 | +export const cleanupDeletedUserFirestoreData = functions |
| 6 | + .region("asia-northeast3") |
| 7 | + .auth |
| 8 | + .user() |
| 9 | + .onDelete(async (user) => { |
| 10 | + const uid = user.uid; |
19 | 11 |
|
20 | 12 | try { |
21 | 13 | const userDocRef = admin.firestore().doc(`users/${uid}`); |
22 | 14 | await admin.firestore().recursiveDelete(userDocRef); |
23 | | - |
24 | | - // Firestore의 recursiveDelete API 사용 (firebase-tools v9.12.0+) |
25 | | - // 실제로는 admin SDK엔 없고, 아래처럼 functions에서 사용할 수 있음 |
26 | | - // https://firebase.google.com/docs/firestore/solutions/delete-collections?hl=ko#cloud-functions |
27 | | - // @ts-ignore |
28 | | - return { success: true } |
29 | | - } catch (err: any) { |
30 | | - throw new HttpsError("internal", `삭제 중 오류: ${err.message || err}`); |
| 15 | + logger.info("Deleted Firestore user data after Auth user deletion", { uid }); |
| 16 | + } catch (error) { |
| 17 | + logger.error("Failed to delete Firestore user data after Auth user deletion", { |
| 18 | + uid, |
| 19 | + error |
| 20 | + }); |
| 21 | + throw error; |
31 | 22 | } |
32 | 23 | } |
33 | 24 | ); |
0 commit comments