mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-04-28 07:19:41 +00:00
31 lines
733 B
JavaScript
31 lines
733 B
JavaScript
|
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;
|
||
|
}
|
||
|
|
||
|
const apiKey = await ApiKey.get(`secret = '${bearerKey}'`);
|
||
|
if (!apiKey) {
|
||
|
response.status(403).json({
|
||
|
error: "No valid api key found.",
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
next();
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
validApiKey,
|
||
|
};
|