diff options
| author | Pitu <[email protected]> | 2019-02-26 22:26:35 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-02-26 22:26:35 +0900 |
| commit | ab66e095a8255f38dba4661951cc0359f309c403 (patch) | |
| tree | d548462d4803f3d274db552e8cb9e5fe237bc467 /src/api/structures/Route.js | |
| parent | User promotion/demotion (diff) | |
| download | host.fuwn.me-ab66e095a8255f38dba4661951cc0359f309c403.tar.xz host.fuwn.me-ab66e095a8255f38dba4661951cc0359f309c403.zip | |
Added adminOnly routes
Diffstat (limited to 'src/api/structures/Route.js')
| -rw-r--r-- | src/api/structures/Route.js | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/api/structures/Route.js b/src/api/structures/Route.js index 60c8b06..a359488 100644 --- a/src/api/structures/Route.js +++ b/src/api/structures/Route.js @@ -33,7 +33,7 @@ class Route { return JWT.verify(token, process.env.SECRET, async (error, decoded) => { if (error) { log.error(error); - return res.status(401).json({ message: 'Your token appears to be invalid' }); + return res.status(401).json({ message: 'Invalid token' }); } const id = decoded ? decoded.sub : ''; const iat = decoded ? decoded.iat : ''; @@ -42,6 +42,7 @@ class Route { if (!user) return res.status(401).json({ message: 'Invalid authorization' }); if (iat && iat < moment(user.passwordEditedAt).format('x')) return res.status(401).json({ message: 'Token expired' }); if (!user.enabled) return res.status(401).json({ message: 'This account has been disabled' }); + if (this.options.adminOnly && !user.isAdmin) return res.status(401).json({ message: 'Invalid authorization' }); return this.run(req, res, db, user); }); |