File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
app/api/kiloclaw/chat-credentials Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 11import { NextResponse } from 'next/server' ;
2+ import { TRPCError } from '@trpc/server' ;
23import { getUserFromAuth } from '@/lib/user.server' ;
34import { KiloClawUserClient } from '@/lib/kiloclaw/kiloclaw-user-client' ;
45import { KiloClawApiError } from '@/lib/kiloclaw/kiloclaw-internal-client' ;
56import { generateApiToken , TOKEN_EXPIRY } from '@/lib/tokens' ;
7+ import { requireKiloClawAccess } from '@/lib/kiloclaw/access-gate' ;
68
79export async function GET ( ) {
810 const { user, authFailedResponse } = await getUserFromAuth ( {
911 adminOnly : false ,
1012 } ) ;
1113 if ( authFailedResponse ) return authFailedResponse ;
1214
15+ try {
16+ await requireKiloClawAccess ( user . id ) ;
17+ } catch ( err ) {
18+ if ( err instanceof TRPCError && err . code === 'FORBIDDEN' ) {
19+ return NextResponse . json ( { error : err . message } , { status : 403 } ) ;
20+ }
21+ throw err ;
22+ }
23+
1324 try {
1425 const token = generateApiToken ( user , undefined , {
1526 expiresIn : TOKEN_EXPIRY . fiveMinutes ,
Original file line number Diff line number Diff line change @@ -484,7 +484,7 @@ export const kiloclawRouter = createTRPCRouter({
484484 }
485485 } ) ,
486486
487- getStreamChatCredentials : baseProcedure . query ( async ( { ctx } ) => {
487+ getStreamChatCredentials : clawAccessProcedure . query ( async ( { ctx } ) => {
488488 const client = new KiloClawInternalClient ( ) ;
489489 return client . getStreamChatCredentials ( ctx . user . id ) ;
490490 } ) ,
You can’t perform that action at this time.
0 commit comments