diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js index c16f76caca..ac436399a9 100644 --- a/packages/server/src/api/controllers/auth.js +++ b/packages/server/src/api/controllers/auth.js @@ -55,7 +55,8 @@ exports.authenticate = async ctx => { } // if in cloud add the user api key if (environment.CLOUD) { - payload.apiKey = getAPIKey(ctx.user.appId) + const { apiKey } = await getAPIKey(ctx.user.appId) + payload.apiKey = apiKey } const token = jwt.sign(payload, ctx.config.jwtSecret, { diff --git a/packages/server/src/middleware/authenticated.js b/packages/server/src/middleware/authenticated.js index 126d616e3b..93ee66b6d4 100644 --- a/packages/server/src/middleware/authenticated.js +++ b/packages/server/src/middleware/authenticated.js @@ -45,7 +45,7 @@ module.exports = async (ctx, next) => { try { const jwtPayload = jwt.verify(appToken, ctx.config.jwtSecret) - + ctx.apiKey = jwtPayload.apiKey ctx.user = { ...jwtPayload, accessLevel: await getAccessLevel( diff --git a/packages/server/src/utilities/usageQuota.js b/packages/server/src/utilities/usageQuota.js index 95fc76140f..813cbc402d 100644 --- a/packages/server/src/utilities/usageQuota.js +++ b/packages/server/src/utilities/usageQuota.js @@ -22,7 +22,7 @@ function buildUpdateParams(key, property, usage) { return { primary: key, condition: - "#quota.#prop < #limits.#prop AND #quotaReset > :now AND attribute_exists(#quota) AND attribute_exists(#limits)", + "attribute_exists(#quota) AND attribute_exists(#limits) AND #quota.#prop < #limits.#prop AND #quotaReset > :now", expression: "ADD #quota.#prop :usage", names: { "#quota": "usageQuota", @@ -95,6 +95,6 @@ exports.update = async (apiKey, property, usage) => { return } } - throw "Resource limits have been reached" + throw err } }