mirror of
https://github.com/wassname/talk.git
synced 2026-08-20 12:50:41 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
@@ -1,25 +1,29 @@
|
||||
const {passport} = require('../services/passport');
|
||||
const { passport } = require('../services/passport');
|
||||
const debug = require('debug')('talk:middleware:authentication');
|
||||
|
||||
const authentication = (req, res, next) => passport.authenticate('jwt', {
|
||||
session: false
|
||||
}, (err, user) => {
|
||||
if (err) {
|
||||
debug(`cannot get the user: ${err}`);
|
||||
return next(err);
|
||||
}
|
||||
const authentication = (req, res, next) =>
|
||||
passport.authenticate(
|
||||
'jwt',
|
||||
{
|
||||
session: false,
|
||||
},
|
||||
(err, user) => {
|
||||
if (err) {
|
||||
debug(`cannot get the user: ${err}`);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (user) {
|
||||
if (user) {
|
||||
debug('user was on request');
|
||||
|
||||
debug('user was on request');
|
||||
// Attach the user to the request object, now that we know it exists.
|
||||
req.user = user;
|
||||
} else {
|
||||
debug('user was not on request');
|
||||
}
|
||||
|
||||
// Attach the user to the request object, now that we know it exists.
|
||||
req.user = user;
|
||||
} else {
|
||||
debug('user was not on request');
|
||||
}
|
||||
|
||||
next();
|
||||
})(req, res, next);
|
||||
next();
|
||||
}
|
||||
)(req, res, next);
|
||||
|
||||
module.exports = authentication;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
@@ -3,7 +3,6 @@ const pubsub = require('../services/pubsub');
|
||||
// To handle dependancy injection safer, we inject the pubsub handle onto the
|
||||
// request object.
|
||||
module.exports = (req, res, next) => {
|
||||
|
||||
// Attach the pubsub handle to the requests.
|
||||
req.pubsub = pubsub.getClient();
|
||||
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
const SettingsService = require('../services/settings');
|
||||
|
||||
const {
|
||||
BASE_URL,
|
||||
BASE_PATH,
|
||||
MOUNT_PATH,
|
||||
STATIC_URL,
|
||||
} = require('../url');
|
||||
const { BASE_URL, BASE_PATH, MOUNT_PATH, STATIC_URL } = require('../url');
|
||||
|
||||
const {
|
||||
RECAPTCHA_PUBLIC,
|
||||
WEBSOCKET_LIVE_URI,
|
||||
} = require('../config');
|
||||
const { RECAPTCHA_PUBLIC, WEBSOCKET_LIVE_URI } = require('../config');
|
||||
|
||||
// TEMPLATE_LOCALS stores the static data that is provided as a `text/json` on
|
||||
// to the client from the template.
|
||||
@@ -27,7 +19,7 @@ const TEMPLATE_LOCALS = {
|
||||
};
|
||||
|
||||
// attachStaticLocals will attach the locals to the response only.
|
||||
const attachStaticLocals = (locals) => {
|
||||
const attachStaticLocals = locals => {
|
||||
for (const key in TEMPLATE_LOCALS) {
|
||||
const value = TEMPLATE_LOCALS[key];
|
||||
|
||||
@@ -36,11 +28,9 @@ const attachStaticLocals = (locals) => {
|
||||
};
|
||||
|
||||
module.exports = async (req, res, next) => {
|
||||
|
||||
try {
|
||||
|
||||
// Attach the custom css url.
|
||||
const {customCssUrl} = await SettingsService.retrieve('customCssUrl');
|
||||
const { customCssUrl } = await SettingsService.retrieve('customCssUrl');
|
||||
res.locals.customCssUrl = customCssUrl;
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
|
||||
Reference in New Issue
Block a user