Deletion

This guide will help you enable and manage the deletion of organizations in the Next.js Supabase SaaS template, including permissions, subscription handling, and feature flag configurations.

Overview

In the Next.js Supabase SaaS, organizations are a key feature that supports grouping users into manageable units. While deleting an organization is possible, it is generally not recommended. However, if needed, the feature can be enabled within the template.

Enabling Organization Deletion

To allow the deletion of organizations, you must enable the enableOrganizationDeletion flag in the client.config.ts file. By default, this flag is set to true, but you can adjust it as needed:

featuresFlag: {
    enableOrganizationDeletion: true,
}

Permissions for Deleting an Organization

Only two roles have the authority to delete an organization:

  • Organization Owner
  • SuperAdmin

Conditions for Organization Deletion

An organization can only be deleted if:

  1. Billing is canceled or has expired.

    Attempting to delete an organization with an active subscription will prompt a notification, informing the user that deletion cannot be performed while a subscription is still active.

  2. Subscriptions have expired or been canceled.

    After canceling or allowing the subscription to expire, the organization can be successfully removed.

Deletion Process Overview

Once the conditions for deletion are met, the process involves:

  1. Cancel Active Subscriptions: All active subscriptions associated with the organization are canceled using the stripe.subscriptions.cancel method.
  2. Delete the Organization: The organization is removed from the Supabase database.
  3. Redirect the User: After deletion, the user is redirected to the main page of the template.

On this page