如何将远程挂钩添加到环回内置模型中?

问题描述:

每当有人尝试登录到我的应用程序时,我都想注销。我如何通过在内置用户模型的login方法中添加远程钩子来实现这一点?如何将远程挂钩添加到环回内置模型中?

我添加了一个启动脚本server/boot下做到这一点

module.exports = function(app) { 
const User = app.models.User; 
timestamp = new Date(); 
User.afterRemote('login', function (ctx, modelInstance, next) { 
    console.log(ctx.req.body.email, 'has logged in at', timestamp); 
    next(); 
}); 
User.afterRemoteError('login', function(ctx, next) { 
    console.log(ctx.req.body.email, 'has unsuccessfully tried to login at', timestamp); 
    next(); 
}); 
} 

docs

扩展内置的用户模型来创建自己的模型,代表用户或客户;此模型提供注册,登录和恢复密码的功能。扩展内置用户模型时,请使用“用户”以外的模型名称,例如“客户”或“客户端”。不要将其命名为“用户”,因为这会与内置的用户模型发生冲突。