Skip to content

Commit 5ca0844

Browse files
authored
Merge pull request #13 from RooCodeInc/cte/require-org
2 parents de2fbbe + 6fa2a02 commit 5ca0844

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/app/api/events/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ import { cloudEventSchema } from '@/schemas';
66
import { captureEvent } from '@/lib/server/analytics';
77

88
export async function POST(request: NextRequest) {
9-
const { userId } = await auth();
9+
const { userId, orgId } = await auth();
1010

1111
if (!userId) {
1212
return NextResponse.json(
13-
{ error: 'Unauthorized request' },
13+
{ error: 'Unauthorized: User required' },
14+
{ status: 401 },
15+
);
16+
}
17+
18+
if (!orgId) {
19+
return NextResponse.json(
20+
{ error: 'Unauthorized: Organization required' },
1421
{ status: 401 },
1522
);
1623
}
@@ -29,7 +36,7 @@ export async function POST(request: NextRequest) {
2936
}
3037

3138
try {
32-
await captureEvent({ id, userId, timestamp, event: result.data });
39+
await captureEvent({ id, orgId, userId, timestamp, event: result.data });
3340
} catch (error) {
3441
console.error(error);
3542

src/db/clickhouse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CREATE TABLE default.events
44
(
55
-- Shared
66
`id` UUID,
7+
`orgId` String,
78
`userId` String,
89
`timestamp` Int32,
910
`type` String,

src/lib/server/analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const client = createClient({
1111

1212
type AnalyticsEvent = {
1313
id: string;
14+
orgId: string;
1415
userId: string;
1516
timestamp: number;
1617
event: CloudEvent;

0 commit comments

Comments
 (0)