budibase/packages/backend-core/src/middleware/builderOrAdmin.ts

12 lines
360 B
TypeScript
Raw Normal View History

import { UserCtx } from "@budibase/types"
import { isBuilder, isAdmin } from "../users"
import { getAppId } from "../context"
export default async (ctx: UserCtx, next: any) => {
const appId = getAppId()
if (!ctx.internal && !isBuilder(ctx.user, appId) && !isAdmin(ctx.user)) {
ctx.throw(403, "Admin/Builder user only endpoint.")
2022-06-01 16:20:56 +02:00
}
return next()
}