Skip to content

Commit 3c08faa

Browse files
committed
feat: update organization deletion method to use better-auth's API
1 parent a97b3ed commit 3c08faa

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

apps/account/src/hooks/useSession.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,13 @@ export function useCreateOrganization() {
249249
}
250250

251251
/**
252-
* Hook: cascade-delete an organization.
252+
* Hook: delete an organization via better-auth.
253253
*
254254
* Wraps `client.organizations.delete(id)` (which hits
255-
* `DELETE /api/v1/cloud/organizations/:id`). The server tears down every
256-
* project owned by the organization (including each project's physical
257-
* database) before dropping the org row itself.
255+
* `POST /api/v1/auth/organization/delete`). better-auth removes the
256+
* organization, its members and pending invitations; server-side hooks
257+
* (attached to the organization plugin) tear down any projects /
258+
* per-project databases that belonged to the org.
258259
*
259260
* On success the local session + organization list are refreshed so the
260261
* deleted org disappears from the switcher and `activeOrganizationId`

packages/client/src/index.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -963,25 +963,21 @@ export class ObjectStackClient {
963963
},
964964

965965
/**
966-
* Cascade-delete an organization: tears down every project owned by the
967-
* org (including each project's physical database), then drops the
968-
* organization itself (members + invitations are removed by better-auth's
969-
* organization plugin, or the row is deleted directly if the plugin is
970-
* not loaded).
966+
* Delete an organization via better-auth's organization plugin.
971967
*
972-
* DELETE /api/v1/cloud/organizations/:id
968+
* POST /api/v1/auth/organization/delete
969+
*
970+
* better-auth removes the organization row, all members, and all
971+
* pending invitations. Project teardown (per-project DBs, etc.) is
972+
* handled server-side by hooks attached to the organization plugin.
973973
*/
974974
delete: async (organizationId: string) => {
975-
const res = await this.fetch(
976-
`${this.baseUrl}/api/v1/cloud/organizations/${encodeURIComponent(organizationId)}`,
977-
{ method: 'DELETE' },
978-
);
979-
return this.unwrapResponse<{
980-
deleted: boolean;
981-
organizationId: string;
982-
deletedProjects: number;
983-
warnings: string[];
984-
}>(res);
975+
const route = this.getRoute('auth');
976+
const res = await this.fetch(`${this.baseUrl}${route}/organization/delete`, {
977+
method: 'POST',
978+
body: JSON.stringify({ organizationId }),
979+
});
980+
return res.json();
985981
},
986982
};
987983

0 commit comments

Comments
 (0)