Merge pull request #13 from RooCodeInc/cte/require-org

This commit is contained in:
Chris Estreich 2025-05-15 15:33:17 -07:00 committed by GitHub
commit 5ca0844aec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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;