Fixing some bugs with JWT creation not getting an API key.
This commit is contained in:
parent
89d02357b8
commit
c3380d8ab4
|
@ -55,7 +55,7 @@ exports.authenticate = async ctx => {
|
||||||
}
|
}
|
||||||
// if in cloud add the user api key
|
// if in cloud add the user api key
|
||||||
if (environment.CLOUD) {
|
if (environment.CLOUD) {
|
||||||
payload.apiKey = getAPIKey(ctx.user.appId)
|
payload.apiKey = await getAPIKey(ctx.user.appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = jwt.sign(payload, ctx.config.jwtSecret, {
|
const token = jwt.sign(payload, ctx.config.jwtSecret, {
|
||||||
|
|
|
@ -69,13 +69,16 @@ exports.update = async (apiKey, property, usage) => {
|
||||||
try {
|
try {
|
||||||
await apiKeyTable.update(buildUpdateParams(apiKey, property, usage))
|
await apiKeyTable.update(buildUpdateParams(apiKey, property, usage))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// conditional check means the condition failed, need to check why
|
||||||
if (err.code === "ConditionalCheckFailedException") {
|
if (err.code === "ConditionalCheckFailedException") {
|
||||||
// get the API key so we can check it
|
// get the API key so we can check it
|
||||||
const keyObj = await apiKeyTable.get({ primary: apiKey })
|
const keyObj = await apiKeyTable.get({ primary: apiKey })
|
||||||
// the usage quota or usage limits didn't exist
|
// the usage quota or usage limits didn't exist
|
||||||
if (keyObj && (keyObj.usageQuota == null || keyObj.usageLimits == null)) {
|
if (keyObj && (keyObj.usageQuota == null || keyObj.usageLimits == null)) {
|
||||||
keyObj.usageQuota = DEFAULT_USAGE
|
keyObj.usageQuota =
|
||||||
keyObj.usageLimits = DEFAULT_PLAN
|
keyObj.usageQuota == null ? DEFAULT_USAGE : keyObj.usageQuota
|
||||||
|
keyObj.usageLimits =
|
||||||
|
keyObj.usageLimits == null ? DEFAULT_PLAN : keyObj.usageLimits
|
||||||
keyObj.quotaReset = getNewQuotaReset()
|
keyObj.quotaReset = getNewQuotaReset()
|
||||||
await apiKeyTable.put({ item: keyObj })
|
await apiKeyTable.put({ item: keyObj })
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue