Skip to content

Commit 2229610

Browse files
committed
Added auth to the sync
1 parent 67ec4f0 commit 2229610

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

apps/webapp/app/routes/sync.traces.$traceId.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { LoaderFunctionArgs } from "@remix-run/node";
2+
import { $replica } from "~/db.server";
23
import { env } from "~/env.server";
34
import { logger } from "~/services/logger.server";
45
import { getUserId, requireUserId } from "~/services/session.server";
@@ -10,10 +11,32 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
1011
logger.log(`/sync/traces/${params.traceId}`, { userId });
1112

1213
if (!userId) {
13-
return new Response("authorization header not found", { status: 401 });
14+
return new Response("No user found in cookie", { status: 401 });
1415
}
1516

16-
//todo check the user has access to this trace
17+
const trace = await $replica.taskEvent.findFirst({
18+
select: {
19+
organizationId: true,
20+
},
21+
where: {
22+
traceId: params.traceId,
23+
},
24+
});
25+
26+
if (!trace) {
27+
return new Response("No trace found", { status: 404 });
28+
}
29+
30+
const member = await $replica.orgMember.findFirst({
31+
where: {
32+
organizationId: trace.organizationId,
33+
userId,
34+
},
35+
});
36+
37+
if (!member) {
38+
return new Response("Not a member of this org", { status: 401 });
39+
}
1740

1841
const url = new URL(request.url);
1942
const originUrl = new URL(`${env.ELECTRIC_ORIGIN}/v1/shape/public."TaskEvent"`);

0 commit comments

Comments
 (0)