Initial Commit
This commit is contained in:
commit
6d2e379a0c
41 changed files with 5064 additions and 0 deletions
18
src/web/middlewares/auth.js
Normal file
18
src/web/middlewares/auth.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { config } from "../../config.js";
|
||||
|
||||
function authMiddleware(req, res, next) {
|
||||
if (!config.webApiKey) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const header = req.headers.authorization || "";
|
||||
const token = header.replace("Bearer ", "");
|
||||
|
||||
if (token === config.webApiKey) {
|
||||
return next();
|
||||
}
|
||||
|
||||
return res.status(401).json({ error: "Unauthorized" });
|
||||
}
|
||||
|
||||
export { authMiddleware };
|
||||
Loading…
Add table
Add a link
Reference in a new issue