firestorenのfunctionsでユーザーを削除

June 12, 2024

Table of Contents

ログイン中にほかのユーザー削除

// 第2世代
import * as functions from 'firebase-functions/v2';
import * as admin from 'firebase-admin';

export const deleteUser = functions.https.onCall(async (request): Promise<void> => {
  try {
    if (!request.auth) {
      throw new functions.https.HttpsError('unauthenticated', 'error');
    }

    await admin.auth().deleteUser(request.data.userId);

  } catch (error: any) {
    console.error(error);
  }
});