api/core: fix & clean up auth middleware

This commit is contained in:
wukko 2024-08-17 00:59:59 +06:00
parent 30c51b9fe8
commit 974b98f0ac
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -99,8 +99,11 @@ export function runAPI(express, app, __dirname) {
}));
app.post('/', (req, res, next) => {
if (!env.turnstileSecret || !env.jwtSecret) {
return next();
}
try {
if (env.turnstileSecret && env.jwtSecret) {
const authorization = req.header("Authorization");
if (!authorization) {
return fail(res, "error.api.auth.jwt.missing");
@ -127,11 +130,10 @@ export function runAPI(express, app, __dirname) {
}
req.authorized = true;
next();
}
} catch {
return fail(res, "error.api.generic");
}
next();
});
app.post('/', apiLimiter);