{"record":{"id":"099456296b5c60b2","repo":"Stirling-Tools/Stirling-PDF","slug":"error-message-supabase-deletion-failed","errorCode":null,"errorMessage":"error.message || Supabase deletion failed","messagePattern":"error\\.message \\|\\| Supabase deletion failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"frontend/editor/src/saas/services/userManagementService.ts","lineNumber":198,"sourceCode":"    user: User,\n    options?: { notifyUser?: boolean },\n  ): Promise<void> {\n    if (isSupabaseConfigured && supabase) {\n      if (!user.email) {\n        throw new Error(\n          \"Email missing for this user. Please contact support for manual removal.\",\n        );\n      }\n\n      const { error } = await supabase.functions.invoke(\"delete-user\", {\n        body: {\n          target_email: user.email,\n          notify_user: options?.notifyUser ?? true,\n        },\n      });\n\n      if (error) {\n        throw new Error(error.message || \"Supabase deletion failed\");\n      }\n      return;\n    }\n  },\n\n  /**\n   * Invite users via email (admin only)\n   * Sends comma-separated email addresses, creates accounts with random passwords,\n   * and sends invitation emails\n   */\n  async inviteUsers(data: InviteUsersRequest): Promise<InviteUsersResponse> {\n    const formData = new FormData();\n    formData.append(\"emails\", data.emails);\n    formData.append(\"role\", data.role);\n    if (data.teamId) {\n      formData.append(\"teamId\", data.teamId.toString());\n    }\n","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/saas/services/userManagementService.ts#L180-L216","documentation":"Thrown by userManagementService.deleteUser() when the delete-user Supabase edge function returns an error object after the target_email was already validated. The error message prioritizes error.message (the Supabase FunctionsError detail) and falls back to a generic string. This is distinct from error 189 which is the self-service path; this is the admin-initiated deletion.","triggerScenarios":"The edge function fails after receiving the request — target user not found, admin lacks service-role permissions, Stripe redaction of the target user's subscription fails, or the Supabase admin auth API call errors.","commonSituations":"Target user was already deleted (race condition); SUPABASE_SERVICE_ROLE_KEY missing or invalid in the edge function; target user has an active Stripe subscription that can't be cancelled; edge function internal error.","solutions":["Read error.message for the specific edge function error reason","Verify the target user still exists in the Supabase auth users table","Check the delete-user edge function logs for the server-side stack trace","Ensure the edge function has STRIPE_SECRET_KEY and SUPABASE_SERVICE_ROLE_KEY configured","Confirm the admin invoking the deletion has the correct role/permissions"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Confirm the target user still exists before deletion\nconst { data } = await supabase.auth.admin.getUserById(user.id);\nif (!data?.user) {\n  showAdminError('This user no longer exists.');\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await deleteUser(user, { notifyUser: true });\n  await refreshUserList();\n} catch (e) {\n  const msg = e instanceof Error ? e.message : 'Deletion failed';\n  if (msg.includes('not found')) {\n    setAdminError('User not found — they may have already been deleted.');\n    await refreshUserList();\n  } else {\n    setAdminError(msg);\n  }\n}","preventionTips":["Verify SUPABASE_SERVICE_ROLE_KEY and STRIPE_SECRET_KEY are configured in the delete-user edge function","Confirm the target user still exists before attempting deletion","Check the edge function logs for the server-side error detail","Handle 'not found' gracefully as the user may have been deleted by another admin"],"tags":["user-management","admin","edge-function","supabase","deletion","saas"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}