2022-11-23 19:25:20 +01:00
|
|
|
import env from "../environment"
|
|
|
|
import { constants } from "@budibase/backend-core"
|
|
|
|
import { BBContext } from "@budibase/types"
|
2021-10-04 14:40:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a restricted endpoint in the cloud.
|
|
|
|
* Ensure that the correct API key has been supplied.
|
|
|
|
*/
|
2023-01-11 10:37:37 +01:00
|
|
|
export default async (ctx: BBContext, next: any) => {
|
2021-10-08 19:21:40 +02:00
|
|
|
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
2022-11-23 19:25:20 +01:00
|
|
|
const apiKey = ctx.request.headers[constants.Header.API_KEY]
|
2021-10-04 14:40:50 +02:00
|
|
|
if (apiKey !== env.INTERNAL_API_KEY) {
|
|
|
|
ctx.throw(403, "Unauthorized")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|