salix/loopback/server/middleware/current-user.js

15 lines
388 B
JavaScript
Raw Permalink Normal View History

2017-10-13 14:22:45 +00:00
module.exports = function(options) {
return function(req, res, next) {
if (!req.accessToken)
2017-10-13 14:22:45 +00:00
return next();
let LoopBackContext = require('loopback-context');
let loopbackContext = LoopBackContext.getCurrentContext();
if (loopbackContext)
2017-10-13 14:22:45 +00:00
loopbackContext.set('currentUser', req.accessToken.userId);
2017-10-13 14:22:45 +00:00
next();
};
};