PR comments.
This commit is contained in:
parent
c106c3291a
commit
39bfbdfac1
|
@ -16,6 +16,7 @@ export abstract class BudibaseError extends Error {
|
||||||
export enum ErrorCode {
|
export enum ErrorCode {
|
||||||
USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
|
USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
|
||||||
FEATURE_DISABLED = "feature_disabled",
|
FEATURE_DISABLED = "feature_disabled",
|
||||||
|
INVALID_API_KEY = "invalid_api_key",
|
||||||
HTTP = "http",
|
HTTP = "http",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,3 +86,14 @@ export class FeatureDisabledError extends HTTPError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AUTH
|
||||||
|
|
||||||
|
export class InvalidAPIKeyError extends BudibaseError {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
"Invalid API key - may need re-generated, or user doesn't exist",
|
||||||
|
ErrorCode.INVALID_API_KEY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { decrypt } from "../security/encryption"
|
||||||
import * as identity from "../context/identity"
|
import * as identity from "../context/identity"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { Ctx, EndpointMatcher } from "@budibase/types"
|
import { Ctx, EndpointMatcher } from "@budibase/types"
|
||||||
|
import { InvalidAPIKeyError, ErrorCode } from "../errors"
|
||||||
|
|
||||||
const ONE_MINUTE = env.SESSION_UPDATE_PERIOD
|
const ONE_MINUTE = env.SESSION_UPDATE_PERIOD
|
||||||
? parseInt(env.SESSION_UPDATE_PERIOD)
|
? parseInt(env.SESSION_UPDATE_PERIOD)
|
||||||
|
@ -68,11 +69,7 @@ async function checkApiKey(apiKey: string, populateUser?: Function) {
|
||||||
user: await getUser(userId, tenantId, populateUser),
|
user: await getUser(userId, tenantId, populateUser),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw {
|
throw new InvalidAPIKeyError()
|
||||||
message:
|
|
||||||
"Invalid API key - may need re-generated, or user doesn't exist",
|
|
||||||
name: "InvalidApiKey",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -175,7 +172,7 @@ export default function (
|
||||||
// invalid token, clear the cookie
|
// invalid token, clear the cookie
|
||||||
if (err?.name === "JsonWebTokenError") {
|
if (err?.name === "JsonWebTokenError") {
|
||||||
clearCookie(ctx, Cookie.Auth)
|
clearCookie(ctx, Cookie.Auth)
|
||||||
} else if (err?.name === "InvalidApiKey") {
|
} else if (err?.code === ErrorCode.INVALID_API_KEY) {
|
||||||
ctx.throw(403, err.message)
|
ctx.throw(403, err.message)
|
||||||
}
|
}
|
||||||
// allow configuring for public access
|
// allow configuring for public access
|
||||||
|
|
Loading…
Reference in New Issue