Working on the organization and permissions.

This commit is contained in:
charlesgauthereau
2025-08-24 19:33:42 +02:00
parent 44be8009fd
commit 4ed91c1297
5 changed files with 29 additions and 17 deletions
@@ -22,8 +22,8 @@ export const DeleteOrganizationButton = (props: DeleteOrganizationButtonProps) =
organizationSlug: "default",
});
router.push("/");
toast.success(result.data.actionSuccess?.message || "Organization deleted.");
router.refresh()
} else {
// @ts-ignore
const errorMsg = result?.data?.actionError?.message || result?.data?.actionError?.messageParams?.message || "Failed to delete the organization.";
@@ -222,7 +222,13 @@ export const deleteOrganizationAction = userAction.schema(z.string()).action(
let deletedOrganization: Organization;
try {
deletedOrganization = await deleteOrganization(org.id) as Organization;
// TODO : Improve with better auth, always getting 403 error
// deletedOrganization = await deleteOrganization(org.id) as Organization;
[deletedOrganization] = await db
.delete(drizzleDb.schemas.organization)
.where(eq(drizzleDb.schemas.organization.id, org.id))
.returning();
} catch (authError: any) {
console.error("Auth deletion failed:", authError);
return {
@@ -5,24 +5,32 @@ import { v4 as uuidv4 } from "uuid";
import { db } from "@/db";
import { eq } from "drizzle-orm";
import * as drizzleDb from "@/db";
import {authClient} from "@/lib/auth/auth-client";
import {auth} from "@/lib/auth/auth";
export const deleteUserAction = userAction.schema(z.string()).action(async ({ parsedInput, ctx }) => {
const userId = parsedInput.length > 0 ? parsedInput : ctx.user.id;
const uuid = uuidv4();
const [updatedUser] = await db
.update(drizzleDb.schemas.user)
.set({
email: `${uuid}@portabase.com`,
name: `${uuid}`,
//deleted: true,
//todo: add deleted
})
// const [updatedUser] = await db
// .update(drizzleDb.schemas.user)
// .set({
// email: `${uuid}@portabase.com`,
// name: `${uuid}`,
// //deleted: true,
// //todo: add deleted
// })
// .where(eq(drizzleDb.schemas.user.id, userId))
// .returning();
const [deletedUser] = await db
.delete(drizzleDb.schemas.user)
.where(eq(drizzleDb.schemas.user.id, userId))
.returning();
return {
data: updatedUser,
data: deletedUser,
};
});