mirror of
https://github.com/wassname/talk.git
synced 2026-08-16 11:29:31 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
* authorization contains the references to the authorization middleware.
|
||||
* @type {Object}
|
||||
*/
|
||||
const authorization = module.exports = {
|
||||
middleware: []
|
||||
};
|
||||
const authorization = (module.exports = {
|
||||
middleware: [],
|
||||
});
|
||||
|
||||
const debug = require('debug')('talk:middleware:authorization');
|
||||
const ErrNotAuthorized = require('../errors').ErrNotAuthorized;
|
||||
@@ -18,7 +18,6 @@ const ErrNotAuthorized = require('../errors').ErrNotAuthorized;
|
||||
* otherwise
|
||||
*/
|
||||
authorization.has = (user, ...roles) => {
|
||||
|
||||
// If no user is specified, then they can't have the roles you want!
|
||||
if (!user) {
|
||||
return false;
|
||||
@@ -31,7 +30,7 @@ authorization.has = (user, ...roles) => {
|
||||
|
||||
// If there's a user, and roles, then check to see that the user has at least
|
||||
// one of those roles.
|
||||
return roles.some((role) => user.role === role);
|
||||
return roles.some(role => user.role === role);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -41,13 +40,11 @@ authorization.has = (user, ...roles) => {
|
||||
* @return {Callback} connect middleware
|
||||
*/
|
||||
authorization.needed = (...roles) => [
|
||||
|
||||
// Insert the pre-needed middlware.
|
||||
...authorization.middleware,
|
||||
|
||||
// Insert the actual middleware to check for the required role.
|
||||
(req, res, next) => {
|
||||
|
||||
// All routes that are wrapepd with this middleware actually require a role.
|
||||
if (!req.user) {
|
||||
debug(`No user on request, returning with ${ErrNotAuthorized}`);
|
||||
@@ -64,5 +61,5 @@ authorization.needed = (...roles) => [
|
||||
|
||||
// Looks like they're allowed!
|
||||
return next();
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user