@budibase/server
Version:
Budibase Web Server
21 lines (17 loc) • 503 B
text/typescript
import { tenancy, utils, context } from "@budibase/backend-core"
import { UserCtx } from "@budibase/types"
export async function ensureTenantAppOwnershipMiddleware(
ctx: UserCtx,
next: any
) {
const appId = await utils.getAppIdFromCtx(ctx)
if (!appId) {
ctx.throw(400, "appId must be provided")
}
const appTenantId = context.getTenantIDFromAppID(appId)
const tenantId = tenancy.getTenantId()
if (appTenantId !== tenantId) {
ctx.throw(403, "Unauthorized")
}
await next()
}