2022-03-15 20:53:05 +01:00
|
|
|
const { Headers } = require("@budibase/backend-core/constants")
|
2022-03-23 17:45:06 +01:00
|
|
|
const { getAppIdFromCtx } = require("@budibase/backend-core/utils")
|
2022-03-15 20:24:34 +01:00
|
|
|
|
|
|
|
module.exports = function ({ requiresAppId } = {}) {
|
|
|
|
return async (ctx, next) => {
|
2022-03-23 17:45:06 +01:00
|
|
|
const appId = await getAppIdFromCtx(ctx)
|
2022-03-15 20:24:34 +01:00
|
|
|
if (requiresAppId && !appId) {
|
|
|
|
ctx.throw(
|
|
|
|
400,
|
|
|
|
`Invalid app ID provided, please check the ${Headers.APP_ID} header.`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if (!ctx.headers[Headers.API_KEY]) {
|
|
|
|
ctx.throw(
|
|
|
|
400,
|
|
|
|
`Invalid API key provided, please check the ${Headers.API_KEY} header.`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
}
|