You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
706 B
29 lines
706 B
const { ApiKey } = require("../../models/apiKeys");
|
|
const { SystemSettings } = require("../../models/systemSettings");
|
|
|
|
async function validApiKey(request, response, next) {
|
|
const multiUserMode = await SystemSettings.isMultiUserMode();
|
|
response.locals.multiUserMode = multiUserMode;
|
|
|
|
const auth = request.header("Authorization");
|
|
const bearerKey = auth ? auth.split(" ")[1] : null;
|
|
if (!bearerKey) {
|
|
response.status(403).json({
|
|
error: "No valid api key found.",
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (!(await ApiKey.get({ secret: bearerKey }))) {
|
|
response.status(403).json({
|
|
error: "No valid api key found.",
|
|
});
|
|
return;
|
|
}
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = {
|
|
validApiKey,
|
|
};
|