2021-10-05 01:40:50 +13:00
|
|
|
const env = require("../environment")
|
2022-01-13 00:32:14 +13:00
|
|
|
const { Headers } = require("@budibase/backend-core/constants")
|
2021-10-05 01:40:50 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a restricted endpoint in the cloud.
|
|
|
|
* Ensure that the correct API key has been supplied.
|
|
|
|
*/
|
|
|
|
module.exports = async (ctx, next) => {
|
2021-10-09 06:21:40 +13:00
|
|
|
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
2021-10-05 01:40:50 +13:00
|
|
|
const apiKey = ctx.request.headers[Headers.API_KEY]
|
|
|
|
if (apiKey !== env.INTERNAL_API_KEY) {
|
|
|
|
ctx.throw(403, "Unauthorized")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|