Skip to content

Commit 65b633d

Browse files
committed
more cleanup
1 parent e53aa40 commit 65b633d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/rpc/src/routers/revenue.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { websitesApi } from "@databuddy/auth";
22
import { and, db, eq, isNull, revenueConfig, websites } from "@databuddy/db";
33
import { createId } from "@databuddy/shared/utils/ids";
4+
import { ORPCError } from "@orpc/server";
45
import { z } from "zod";
56
import type { Context } from "../orpc";
67
import { protectedProcedure } from "../orpc";
8+
import { authorizeWebsiteAccess } from "../utils/auth";
79

810
function generateHash(): string {
911
const bytes = crypto.getRandomValues(new Uint8Array(24));
@@ -55,6 +57,14 @@ export const revenueRouter = {
5557
.handler(async ({ context, input }) => {
5658
const ownerId = await getOwnerId(context, input.websiteId);
5759

60+
if (input.websiteId) {
61+
await authorizeWebsiteAccess(context, input.websiteId, "read");
62+
} else if (!(await hasManagePermission(context.headers, ownerId))) {
63+
throw new ORPCError("FORBIDDEN", {
64+
message: "Missing permissions",
65+
});
66+
}
67+
5868
const config = await context.db.query.revenueConfig.findFirst({
5969
where: input.websiteId
6070
? and(

0 commit comments

Comments
 (0)