mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-09-11 23:03:25 +02:00
* Autodocument Swagger API with JSDocs on /v1/ endpoints for API access implement single-player API keys WIP Admin API Keys * Create new api keys as both single and multi-user * Add boot and telem * Complete Admin API * Complete endpoints dark mode swagger * update docs * undo debug * update docs and readme
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,
|
|
};
|