Base on loopback3 current context package current user for loopback operation hooks
> npm install loopback-component-currentuser
./server/component-config.json
{
...
"loopback-component-currentuser": {
"filter" : {
"include": ["userIdentities", "userCredentials"]
},
"user": "user"
}
...
}
'use strict';
module.exports = (Deal) => {
Deal.observe('before save', (ctx, next)=>{
if (ctx.instance) {
if (ctx.isNewInstance) {
if (ctx.options.accessToken) {
console.log(ctx.options.currentUser);
}
}
next();
} else {
next();
}
});
};