Sample alert How it works Coverage PENTEST METHODOLOGY DOCS PRICING FAQ MCP CONTACT LOG IN SCAN MY APP →

App Store rejected for no account deletion: how to fix it

FIX / GUIDELINE 5.1.1(V) / 10 MIN READ

Apple rejects apps that let users create an account but do not let them delete it inside the app. Add a delete button that calls a server function. Make that function remove the auth user, the rows, the files, and the Sign in with Apple token. The function must also check that the caller is the user who owns the account.

This guide explains what Guideline 5.1.1(v) requires, gives a working Supabase Edge Function, and shows how to answer App Review. It also shows how to avoid a new hole: a delete endpoint that accepts any user ID.

What does Apple require for account deletion?

Apple states the rule on its page Offering account deletion in your app. Apps that support account creation must let people start deletion of the account inside the app. The deletion must remove the account and the data that you are not legally required to keep.

These are the main points from the page:

  • The option must be easy to find. Apple says it is typically in the account settings.
  • Deactivation is not enough. Offering only to temporarily deactivate or disable the account does not pass.
  • The data must go too. This includes user-generated content that other people can see, such as photos, posts, and reviews.
  • Guest accounts count. Automatic guest accounts need a deletion option too.
  • Confirmation is allowed. Apple fails apps that make deletion unnecessarily difficult.
  • Support flows are not allowed. A phone call, an email, or a chat does not pass, except in highly regulated industries.
  • Deletion can take time. Tell the user how long it takes, and confirm when it is complete.

Apple also asks developers who use Sign in with Apple to revoke the user tokens with the Sign in with Apple REST API. The next sections show how.

Why does an AI-built app fail this check?

AI tools build the sign-up, login, and profile screens. They rarely build a delete path, because the prompt did not ask for it.

The code then has one of these partial fixes:

  • Sign out only. The account and the data stay.
  • Profile row only. The row in auth.users stays, and the user can still sign in.
  • Auth user only. The photos and the rows in other tables stay.
  • Client-side admin key. The app contains the service_role key. Anyone who reads the app binary has full access. Read the service_role key guide if you suspect this.

A reviewer taps through the settings. If the button is not there in two or three taps, the review fails. The Apple vs vibe coding report lists other rejection reasons that generated apps hit often.

How do I design the delete flow?

Add a Delete Account button in the settings screen. Show a dialog that says the deletion cannot be undone. Call a server function, then sign out and show a message. If the user has an App Store subscription, show a notice first, because billing continues through Apple. Open showManageSubscriptions on iOS 15 or later.

How do I write the server function?

This example uses a Supabase Edge Function. The same design works with any backend. The function does five things in this order:

  1. Read the caller from the JWT in the Authorization header.
  2. Delete the caller’s files in storage.
  3. Delete the caller’s rows.
  4. Revoke the Sign in with Apple token, if the user signed in with Apple.
  5. Delete the auth user.

The function never reads a user ID from the request body. It uses only the ID from the verified token. This is the check that stops one user from deleting another user.

Create the function:

supabase functions new delete-account

Put this code in supabase/functions/delete-account/index.ts:

import { createClient } from "npm:@supabase/supabase-js@2";

const url = Deno.env.get("SUPABASE_URL")!;
const anonKey = Deno.env.get("SUPABASE_ANON_KEY")!;
const serviceKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;

const json = (body: unknown, status = 200) =>
  new Response(JSON.stringify(body), {
    status,
    headers: { "Content-Type": "application/json" },
  });

Deno.serve(async (req) => {
  if (req.method !== "POST") return json({ error: "Method not allowed" }, 405);

  const authHeader = req.headers.get("Authorization");
  if (!authHeader) return json({ error: "Unauthorized" }, 401);

  // 1. Find the caller from the token. Never read the user ID from the body.
  const userClient = createClient(url, anonKey, {
    global: { headers: { Authorization: authHeader } },
  });
  const { data, error } = await userClient.auth.getUser();
  if (error || !data.user) return json({ error: "Unauthorized" }, 401);
  const user = data.user;

  const admin = createClient(url, serviceKey);

  // 2. Delete the files of the user.
  const removed = await removeFolder(admin, "avatars", user.id);
  if (!removed) return json({ error: "Storage delete failed" }, 500);

  // 3. Delete the rows of the user.
  for (const table of ["messages", "posts", "profiles"]) {
    const { error: rowError } = await admin.from(table).delete().eq("user_id", user.id);
    if (rowError) return json({ error: `Delete failed in ${table}` }, 500);
  }

  // 4. Revoke the Sign in with Apple token.
  const usesApple = user.identities?.some((i) => i.provider === "apple");
  if (usesApple) {
    const { appleAuthorizationCode } = await req.json().catch(() => ({}));
    const revoked = await revokeApple(appleAuthorizationCode);
    if (!revoked) return json({ error: "Apple revoke failed" }, 502);
  }

  // 5. Delete the auth user.
  const { error: deleteError } = await admin.auth.admin.deleteUser(user.id);
  if (deleteError) return json({ error: "Auth delete failed" }, 500);

  return json({ deleted: true });
});

The helper removeFolder deletes every file under <bucket>/<user id>/. It handles one folder level. A deeper layout needs a loop.

// deno-lint-ignore no-explicit-any
async function removeFolder(admin: any, bucket: string, prefix: string): Promise<boolean> {
  const { data: items, error } = await admin.storage.from(bucket).list(prefix, { limit: 1000 });
  if (error) return false;
  if (!items?.length) return true;

  const paths = items.map((item: { name: string }) => `${prefix}/${item.name}`);
  const { error: removeError } = await admin.storage.from(bucket).remove(paths);
  return !removeError;
}

This code expects that the app stores each file under a folder that has the user ID as its name, for example avatars/<user id>/photo.jpg. If your app uses another layout, change the prefix. The storage bucket guide explains why that layout also helps your storage policies.

Caution: The code deletes from messages, posts, and profiles. Replace this list with the tables of your project. Search your migrations for every column that holds a user ID. A table that you forget keeps personal data.

You can also add on delete cascade to each foreign key that points to auth.users. Then deleteUser removes the rows. Check the constraint with \d posts in psql.

How do I check that the caller is the user?

The check is the first part of the function. The call to auth.getUser() asks Supabase Auth to validate the JWT, so a forged token fails. The code uses only user.id, never a value from the request body. The service_role key exists only as a secret of the function.

A common AI-written version has no check:

// WRONG: any caller can delete any user
const { userId } = await req.json();
await admin.auth.admin.deleteUser(userId);

A stranger who finds the function URL sends any user ID, and the function deletes that user. The Edge Function no-JWT guide shows why a function that skips JWT checks is open to the internet. The guide on deleted rows covers the same class of problem for tables.

Deploy the function with the default setting. Supabase then rejects a request with no valid JWT before your code runs:

supabase functions deploy delete-account

Do not add --no-verify-jwt. Test from outside. A request with no token must fail:

curl -i -X POST https://<project-ref>.supabase.co/functions/v1/delete-account \
  -H "Content-Type: application/json" \
  -d '{"userId":"00000000-0000-0000-0000-000000000000"}'

The result must be 401. Then test with the token of a test user. Warning: Use only a test account. A successful call deletes the account for real.

How do I revoke the Sign in with Apple token?

If the user signed in with Apple, Apple keeps a link between your app and the user. Deleting your own records does not remove that link. Apple asks you to revoke the token with the Sign in with Apple REST API.

The revoke call needs a refresh token or an access token. Supabase does not give you one when the app signs in with an Apple ID token. You must get a new one at deletion time. Use this flow:

  1. The app asks the user to sign in with Apple again. This also confirms that the user means to delete the account.
  2. Apple returns an authorizationCode to the app.
  3. The app sends the code to the function in the request body.
  4. The function exchanges the code for a refresh token at https://appleid.apple.com/auth/token.
  5. The function sends the refresh token to https://appleid.apple.com/auth/revoke.

Both calls need a client_secret. This is a JWT that your server signs with the .p8 key from your Apple Developer account. The claims are iss (Team ID), sub (bundle ID), aud (https://appleid.apple.com), iat, and exp. The header has alg set to ES256 and kid set to the Key ID. Use a short expiry, because the function makes a new secret for each call.

Add this helper to the same file. It uses the jose library:

import { importPKCS8, SignJWT } from "npm:jose@5";

async function revokeApple(code: string | undefined): Promise<boolean> {
  if (!code) return false;

  const key = await importPKCS8(
    Deno.env.get("APPLE_PRIVATE_KEY")!.replace(/\\n/g, "\n"),
    "ES256",
  );
  const clientId = Deno.env.get("APPLE_BUNDLE_ID")!;
  const clientSecret = await new SignJWT({})
    .setProtectedHeader({ alg: "ES256", kid: Deno.env.get("APPLE_KEY_ID")! })
    .setIssuer(Deno.env.get("APPLE_TEAM_ID")!)
    .setSubject(clientId)
    .setAudience("https://appleid.apple.com")
    .setIssuedAt()
    .setExpirationTime("5m")
    .sign(key);

  const tokenResponse = await fetch("https://appleid.apple.com/auth/token", {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: new URLSearchParams({
      client_id: clientId,
      client_secret: clientSecret,
      code,
      grant_type: "authorization_code",
    }),
  });
  if (!tokenResponse.ok) return false;
  const { refresh_token } = await tokenResponse.json();

  const revokeResponse = await fetch("https://appleid.apple.com/auth/revoke", {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: new URLSearchParams({
      client_id: clientId,
      client_secret: clientSecret,
      token: refresh_token,
      token_type_hint: "refresh_token",
    }),
  });
  return revokeResponse.ok;
}

Store the four Apple values as secrets of the function. Do not put them in the app or in Git:

supabase secrets set APPLE_TEAM_ID=<team id> APPLE_KEY_ID=<key id> \
  APPLE_BUNDLE_ID=<bundle id> APPLE_PRIVATE_KEY="$(cat AuthKey_<key id>.p8)"

A successful revoke returns status 200. On an error, check the client_id, the Key ID, and the Team ID first.

Warning: The .p8 file is a signing key. Anyone who has it can make a valid client_secret for your app. Keep it out of the repository, and rotate it in the Apple Developer account if it leaks. The token leak checker helps you find keys in public code.

Apple also sends server notifications when a user turns off the link in the Apple ID settings. Read the Apple page on processing changes for Sign in with Apple accounts.

How do I call the function from the app?

In an Expo or React Native app, the code is short. The call to supabase.functions.invoke sends the JWT of the signed-in user automatically.

import * as AppleAuthentication from "expo-apple-authentication";
import { supabase } from "@/lib/supabase";

export async function deleteAccount(usesApple: boolean) {
  let appleAuthorizationCode: string | null = null;

  if (usesApple) {
    const credential = await AppleAuthentication.signInAsync({ requestedScopes: [] });
    appleAuthorizationCode = credential.authorizationCode;
  }

  const { error } = await supabase.functions.invoke("delete-account", {
    body: { appleAuthorizationCode },
  });
  if (error) throw error;

  await supabase.auth.signOut();
}

If the app keeps data in other services, delete it in the same function. For Stripe, cancel the subscriptions and call stripe.customers.del(customerId). Also remove push tokens, analytics profiles, and email list entries. Apple allows you to keep data that the law requires. Tell the user what you keep.

How do I check that the deletion is complete?

Make a test account with data in every part of the app. Delete it. Then check these places:

  1. Auth. select id from auth.users where email = '<test email>'; returns no row.
  2. Rows. Every table returns zero rows for the old user ID.
  3. Storage. The folder of the user is empty.
  4. Apple. The app is gone from Sign-In & Security, then Sign in with Apple, in the Apple ID settings.
  5. Other services. Stripe and the analytics tool hold no record.

Add a test that fails when a table has a user_id column that the function does not delete.

How do I reply to App Review?

Reply in App Store Connect on the rejection message. Say what you changed and where the reviewer finds it. Keep the text short. Use this template:

Hello,

We added account deletion in version <version> (build <build>).

Path: Settings > Account > Delete Account.
The app shows a confirmation dialog. After the user confirms, the app calls
our server function. The function deletes the account, the user content, and
the files. For Sign in with Apple, the function revokes the user token.

The deletion completes in less than one minute. The app shows a message when it ends.
We keep no personal data after the deletion. <Or list what the law requires you to keep.>

Test account: <email> / <password>

Add a screen recording if the button is in a sub-menu. Give the reviewer a test account with data. Do not argue about the guideline. Fix the app, build again, and submit.

How do I stop this problem in the future?

  1. Ask for deletion with sign-up. Put the delete path in the same prompt as the login screen.
  2. List every place that stores user data. Update the list with each new table or service.
  3. Test the endpoint from outside. Run the curl test with no token and with the token of another user.
  4. Keep keys on the server. Search the app for service_role before each release. The Rork checklist has more pre-release checks.
  5. Scan the backend. A scan finds open endpoints and open storage before a reviewer or an attacker does.

When should I get help?

Get help in these cases:

  • You must keep some data by law and you do not know which data. Ask a lawyer.
  • The app has several backends and you cannot list all of them.
  • You find an admin key in the app. Rotate the key first, then ask an engineer to review the app.

When the fix is ready, run the full check from the previous section on a real build. Then submit the app.

Common questions

Is a Sign Out button enough for Guideline 5.1.1(v)?
No. Sign out keeps the account and the data. Apple requires a way to start deletion of the whole account inside the app.
Can I only deactivate the account?
No. Apple states that offering only to temporarily deactivate or disable an account is not enough. You must offer to delete the account record and the personal data.
Can I ask users to send an email to delete the account?
No, except in highly regulated industries. If you need a website, link directly to the page where the user finishes the deletion.
Does the deletion have to be instant?
No. A reasonable delay is acceptable. Tell the user how long it takes, and confirm when it is done.
Do I need a server function, or can the app delete the user?
You need a server function. Deleting an auth user needs the service_role key, and that key must never be in the app.

Test your app backend

A VibeEval scan checks the web app and API behind your iOS app, and reports open endpoints, open storage buckets, and tables that return data to the wrong caller.

14-day free trial · Cancel anytime

SCAN YOUR APP →