File tree Expand file tree Collapse file tree 6 files changed +21
-9
lines changed
organizations/[id]/invitations/[invitationId] Expand file tree Collapse file tree 6 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 11import { createLogger } from '@sim/logger'
22import { type NextRequest , NextResponse } from 'next/server'
33import { z } from 'zod'
4+ import {
5+ authenticateCopilotRequestSessionOnly ,
6+ createUnauthorizedResponse ,
7+ } from '@/lib/copilot/request-helpers'
48import { env } from '@/lib/core/config/env'
59
610const logger = createLogger ( 'CopilotTrainingExamplesAPI' )
@@ -16,6 +20,11 @@ const TrainingExampleSchema = z.object({
1620} )
1721
1822export async function POST ( request : NextRequest ) {
23+ const { userId, isAuthenticated } = await authenticateCopilotRequestSessionOnly ( )
24+ if ( ! isAuthenticated || ! userId ) {
25+ return createUnauthorizedResponse ( )
26+ }
27+
1928 const baseUrl = env . AGENT_INDEXER_URL
2029 if ( ! baseUrl ) {
2130 logger . error ( 'Missing AGENT_INDEXER_URL environment variable' )
Original file line number Diff line number Diff line change 11import { createLogger } from '@sim/logger'
22import { type NextRequest , NextResponse } from 'next/server'
33import { z } from 'zod'
4+ import {
5+ authenticateCopilotRequestSessionOnly ,
6+ createUnauthorizedResponse ,
7+ } from '@/lib/copilot/request-helpers'
48import { env } from '@/lib/core/config/env'
59
610const logger = createLogger ( 'CopilotTrainingAPI' )
@@ -22,6 +26,11 @@ const TrainingDataSchema = z.object({
2226} )
2327
2428export async function POST ( request : NextRequest ) {
29+ const { userId, isAuthenticated } = await authenticateCopilotRequestSessionOnly ( )
30+ if ( ! isAuthenticated || ! userId ) {
31+ return createUnauthorizedResponse ( )
32+ }
33+
2534 try {
2635 const baseUrl = env . AGENT_INDEXER_URL
2736 if ( ! baseUrl ) {
Original file line number Diff line number Diff line change @@ -62,8 +62,7 @@ export async function GET(
6262 }
6363
6464 // Verify caller is either an org member or the invitee
65- const isInvitee =
66- session . user . email ?. toLowerCase ( ) === orgInvitation . email . toLowerCase ( )
65+ const isInvitee = session . user . email ?. toLowerCase ( ) === orgInvitation . email . toLowerCase ( )
6766
6867 if ( ! isInvitee ) {
6968 const memberEntry = await db
Original file line number Diff line number Diff line change 66 updateApiKeyLastUsed ,
77} from '@/lib/api-key/service'
88import { type AuthResult , checkHybridAuth } from '@/lib/auth/hybrid'
9- import { env } from '@/lib/core/config/env'
109import { authorizeWorkflowByWorkspacePermission , getWorkflowById } from '@/lib/workflows/utils'
1110
1211const logger = createLogger ( 'WorkflowMiddleware' )
@@ -81,11 +80,6 @@ export async function validateWorkflowAccess(
8180 }
8281 }
8382
84- const internalSecret = request . headers . get ( 'X-Internal-Secret' )
85- if ( env . INTERNAL_API_SECRET && internalSecret === env . INTERNAL_API_SECRET ) {
86- return { workflow }
87- }
88-
8983 let apiKeyHeader = null
9084 for ( const [ key , value ] of request . headers . entries ( ) ) {
9185 if ( key . toLowerCase ( ) === 'x-api-key' && value ) {
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ const BEARER_PREFIX = 'Bearer '
2525export function hasExternalApiCredentials ( headers : Headers ) : boolean {
2626 if ( headers . has ( API_KEY_HEADER ) ) return true
2727 const auth = headers . get ( 'authorization' )
28- return auth !== null && auth . startsWith ( BEARER_PREFIX )
28+ return auth ? .startsWith ( BEARER_PREFIX )
2929}
3030
3131export interface AuthResult {
You can’t perform that action at this time.
0 commit comments