aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/passport.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/passport.js b/lib/passport.js
index eafc8179..7bf68c13 100644
--- a/lib/passport.js
+++ b/lib/passport.js
@@ -14,18 +14,18 @@ passport = Passport.use(
{
jwtFromRequest: jwt.ExtractJwt.fromExtractors([
jwt.ExtractJwt.fromAuthHeaderAsBearerToken(),
- cookieExtractor,
+ cookieExtractor
]),
- secretOrKey: config.jwt,
+ secretOrKey: config.jwt
},
async (payload, next) => {
try {
let { username } = payload;
let user = await db.User.findOne({
where: {
- username: { [Op.or]: [username, username.replace(/ /g, "")] },
+ username: { [Op.or]: [username, username.replace(/ /g, "")] }
},
- include: { model: db.Account, as: "account" },
+ include: { model: db.Account, as: "account" }
});
if (user.locked) throw new Error("account is locked");
next(null, user);
@@ -40,19 +40,19 @@ passport = Passport.use(
auth = passport.authenticate("jwt", { session: false });
-optionalAuth = function (req, res, next) {
- passport.authenticate("jwt", { session: false }, function (err, user, info) {
+optionalAuth = function(req, res, next) {
+ passport.authenticate("jwt", { session: false }, function(err, user, info) {
req.user = user;
next();
})(req, res, next);
};
-adminAuth = (req, res, next) => {
- passport.authenticate("jwt", { session: false }, function (err, user, info) {
- if (!(user && user.admin)) throw new Error("restricted");
+adminAuth = ah((req, res, next) => {
+ passport.authenticate("jwt", { session: false }, function(err, user, info) {
+ if (!(user && user.admin)) return res.status(401).send("Unauthorized")
req.user = user;
next();
})(req, res, next);
-};
+});
app.use(passport.initialize());