diff --git a/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts b/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts index e2dbcb516..82d0ffb3e 100644 --- a/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts +++ b/apps/dashboard/lib/trpc/routers/api/setDefaultBytes.ts @@ -18,35 +18,26 @@ export const setDefaultApiBytes = t.procedure }), ) .mutation(async ({ ctx, input }) => { - const workspace = await db.query.workspaces + const keyAuth = await db.query.keyAuth .findFirst({ - where: (table, { eq }) => eq(table.tenantId, ctx.tenant.id), + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyAuthId), isNull(table.deletedAt)), with: { - keySpaces: { - where: (table, { eq }) => eq(table.id, input.keyAuthId), - }, + workspace: true, }, }) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to find the KeyAuth. Please try again or contact support@unkey.dev.", + "We were unable to update the key auth. Please try again or contact support@unkey.dev", }); }); - if (!workspace) { - throw new TRPCError({ - code: "NOT_FOUND", - message: - "We are unable to find the correct workspace. Please try again or contact support@unkey.dev", - }); - } - const keyAuth = workspace.keySpaces.at(0); - if (!keyAuth) { + if (!keyAuth || keyAuth.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct keyAuth. Please try again or contact support@unkey.dev", + "We are unable to find the correct key auth. Please try again or contact support@unkey.dev.", }); } await db @@ -65,7 +56,7 @@ export const setDefaultApiBytes = t.procedure }); }); await insertAuditLogs(tx, { - workspaceId: workspace.id, + workspaceId: keyAuth.workspace.id, actor: { type: "user", id: ctx.user.id, diff --git a/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts b/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts index 8460a7d3f..d5f6feeea 100644 --- a/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts +++ b/apps/dashboard/lib/trpc/routers/api/setDefaultPrefix.ts @@ -14,35 +14,26 @@ export const setDefaultApiPrefix = t.procedure }), ) .mutation(async ({ ctx, input }) => { - const workspace = await db.query.workspaces + const keyAuth = await db.query.keyAuth .findFirst({ - where: (table, { eq }) => eq(table.tenantId, ctx.tenant.id), + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyAuthId), isNull(table.deletedAt)), with: { - keySpaces: { - where: (table, { eq }) => eq(table.id, input.keyAuthId), - }, + workspace: true, }, }) .catch((_err) => { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We were unable to find the KeyAuth. Please try again or contact support@unkey.dev.", + "We were unable to update the key auth. Please try again or contact support@unkey.dev", }); }); - if (!workspace) { - throw new TRPCError({ - code: "NOT_FOUND", - message: - "We are unable to find the correct workspace. Please try again or contact support@unkey.dev", - }); - } - const keyAuth = workspace.keySpaces.at(0); - if (!keyAuth) { + if (!keyAuth || keyAuth.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", message: - "We are unable to find the correct keyAuth. Please try again or contact support@unkey.dev", + "We are unable to find the correct key auth. Please try again or contact support@unkey.dev.", }); } @@ -62,7 +53,7 @@ export const setDefaultApiPrefix = t.procedure }); }); await insertAuditLogs(tx, { - workspaceId: workspace.id, + workspaceId: keyAuth.workspace.id, actor: { type: "user", id: ctx.user.id,