3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 23:25:02 +00:00

dashboard: auth fixes, guild listing, config editing

This commit is contained in:
Dragory 2019-06-23 03:40:53 +03:00
parent 0a1cd81035
commit 5279ab06fa
14 changed files with 200 additions and 42 deletions

View file

@ -59,13 +59,12 @@ export function initAuth(app: express.Express) {
passport.use(
"api-token",
new CustomStrategy(async (req, cb) => {
console.log("in api-token strategy");
const apiKey = req.header("X-Api-Key");
if (!apiKey) return cb();
const userId = await dashboardLogins.getUserIdByApiKey(apiKey);
if (userId) {
cb(null, { userId });
return cb(null, { userId });
}
cb();
@ -111,9 +110,15 @@ export function initAuth(app: express.Express) {
const userId = await dashboardLogins.getUserIdByApiKey(key);
if (!userId) {
return res.status(403).json({ error: "Invalid key" });
return res.json({ valid: false });
}
res.json({ status: "ok" });
res.json({ valid: true });
});
}
export function requireAPIToken(router: express.Router) {
router.use(passport.authenticate("api-token", { failWithError: true }), (err, req, res, next) => {
return res.json({ error: err.message });
});
}