mirror of
https://github.com/wukko/cobalt.git
synced 2025-04-22 18:12:02 +02:00
api/core: fix & clean up auth middleware
This commit is contained in:
parent
30c51b9fe8
commit
974b98f0ac
1 changed files with 30 additions and 28 deletions
|
@ -99,8 +99,11 @@ export function runAPI(express, app, __dirname) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.post('/', (req, res, next) => {
|
app.post('/', (req, res, next) => {
|
||||||
|
if (!env.turnstileSecret || !env.jwtSecret) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (env.turnstileSecret && env.jwtSecret) {
|
|
||||||
const authorization = req.header("Authorization");
|
const authorization = req.header("Authorization");
|
||||||
if (!authorization) {
|
if (!authorization) {
|
||||||
return fail(res, "error.api.auth.jwt.missing");
|
return fail(res, "error.api.auth.jwt.missing");
|
||||||
|
@ -127,11 +130,10 @@ export function runAPI(express, app, __dirname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
req.authorized = true;
|
req.authorized = true;
|
||||||
next();
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
return fail(res, "error.api.generic");
|
return fail(res, "error.api.generic");
|
||||||
}
|
}
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/', apiLimiter);
|
app.post('/', apiLimiter);
|
||||||
|
|
Loading…
Add table
Reference in a new issue