小编Ano*_*cem的帖子

来自beforeSave Model Hook的访问请求标头

如何从模型挂钩中访问提出请求的用户的详细信息

Comment.beforeSave =  function(next,com) {
//Want to add 2 more properties before saving 
com.added_at = new Date();    
com.added_by =  //How can i set the user id here ??
//In case of a Remote hook i have ctx in param and i can get user id like this     ctx.req.accessToken.userId;  But in Model Hook how can i do the same?    
next();    
};
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?我尝试使用远程钩子作为主要项目

MainItem.beforeRemote('**', function(ctx, user, next) {   
if(ctx.methodString == 'leave_request.prototype.__create__comments'){       
    ctx.req.body.added_by = ctx.req.accessToken.userId;     
    ctx.req.body.added_at = new Date();                         
    console.log("Added headers as .."+ctx.req.body.added_by); …
Run Code Online (Sandbox Code Playgroud)

strongloop loopbackjs

7
推荐指数
1
解决办法
4129
查看次数

标签 统计

loopbackjs ×1

strongloop ×1