aboutsummaryrefslogtreecommitdiffstats
path: root/lib/passport.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-12-19 01:35:15 -0500
committerAdam Soltys <[email protected]>2022-02-12 08:18:17 -0500
commit143fb28ba56c462665cd4a402390b3ac081e36df (patch)
tree3a2562a60d22e9e6edd3415c3891465d53464ebe /lib/passport.js
parent2f286df6271db4cce536688804691a801ef6502a (diff)
downloadcoinos-server-143fb28ba56c462665cd4a402390b3ac081e36df.tar.gz
coinos-server-143fb28ba56c462665cd4a402390b3ac081e36df.zip
return error status
Diffstat (limited to 'lib/passport.js')
-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());