Require orgId in events

This commit is contained in:
cte 2025-05-15 15:31:22 -07:00
parent de2fbbe214
commit 6fa2a022f7
3 changed files with 12 additions and 3 deletions

View file

@ -6,11 +6,18 @@ import { cloudEventSchema } from '@/schemas';
import { captureEvent } from '@/lib/server/analytics';
export async function POST(request: NextRequest) {
const { userId } = await auth();
const { userId, orgId } = await auth();
if (!userId) {
return NextResponse.json(
{ error: 'Unauthorized request' },
{ error: 'Unauthorized: User required' },
{ status: 401 },
);
}
if (!orgId) {
return NextResponse.json(
{ error: 'Unauthorized: Organization required' },
{ status: 401 },
);
}
@ -29,7 +36,7 @@ export async function POST(request: NextRequest) {
}
try {
await captureEvent({ id, userId, timestamp, event: result.data });
await captureEvent({ id, orgId, userId, timestamp, event: result.data });
} catch (error) {
console.error(error);

View file

@ -4,6 +4,7 @@ CREATE TABLE default.events
(
-- Shared
`id` UUID,
`orgId` String,
`userId` String,
`timestamp` Int32,
`type` String,

View file

@ -11,6 +11,7 @@ const client = createClient({
type AnalyticsEvent = {
id: string;
orgId: string;
userId: string;
timestamp: number;
event: CloudEvent;