11import { renderedOrganizationConfigToProjectCrud } from "@/lib/config" ;
2- import { getPrismaClientForTenancy } from "@/prisma-client" ;
32import { createOrUpdateProjectWithLegacyConfig , getProjectQuery , listManagedProjectIds } from "@/lib/projects" ;
43import { ensureTeamMembershipExists } from "@/lib/request-checks" ;
54import { DEFAULT_BRANCH_ID , getSoleTenancyFromProjectBranch } from "@/lib/tenancies" ;
6- import { globalPrismaClient , rawQueryAll } from "@/prisma-client" ;
5+ import { getPrismaClientForTenancy , globalPrismaClient , rawQueryAll } from "@/prisma-client" ;
76import { createCrudHandlers } from "@/route-handlers/crud-handler" ;
87import { KnownErrors } from "@stackframe/stack-shared" ;
98import { adminUserProjectsCrud } from "@stackframe/stack-shared/dist/interface/crud/projects" ;
@@ -17,14 +16,17 @@ export const adminUserProjectsCrudHandlers = createLazyProxy(() => createCrudHan
1716 projectId : projectIdSchema . defined ( ) ,
1817 } ) ,
1918 onPrepare : async ( { auth } ) => {
19+ if ( auth . project . id !== "internal" ) {
20+ throw new KnownErrors . ExpectedInternalProject ( ) ;
21+ }
2022 if ( ! auth . user ) {
2123 throw new KnownErrors . UserAuthenticationRequired ;
2224 }
25+ } ,
26+ onCreate : async ( { auth, data } ) => {
2327 if ( auth . project . id !== "internal" ) {
2428 throw new KnownErrors . ExpectedInternalProject ( ) ;
2529 }
26- } ,
27- onCreate : async ( { auth, data } ) => {
2830 const user = auth . user ?? throwErr ( 'auth.user is required' ) ;
2931 const prisma = await getPrismaClientForTenancy ( auth . tenancy ) ;
3032 await ensureTeamMembershipExists ( prisma , {
@@ -51,6 +53,12 @@ export const adminUserProjectsCrudHandlers = createLazyProxy(() => createCrudHan
5153 } ;
5254 } ,
5355 onList : async ( { auth } ) => {
56+ if ( auth . project . id !== "internal" ) {
57+ throw new KnownErrors . ExpectedInternalProject ( ) ;
58+ }
59+ if ( ! auth . user ) {
60+ throw new KnownErrors . UserAuthenticationRequired ( ) ;
61+ }
5462 const projectIds = await listManagedProjectIds ( auth . user ?? throwErr ( 'auth.user is required' ) ) ;
5563 const projectsRecord = await rawQueryAll ( globalPrismaClient , typedFromEntries ( projectIds . map ( ( id , index ) => [ index , getProjectQuery ( id ) ] ) ) ) ;
5664 const projects = ( await Promise . all ( typedEntries ( projectsRecord ) . map ( async ( [ _ , project ] ) => await project ) ) ) . filter ( isNotNull ) ;
0 commit comments