如何将远程挂钩添加到环回内置模型中?
答
我添加了一个启动脚本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:
扩展内置的用户模型来创建自己的模型,代表用户或客户;此模型提供注册,登录和恢复密码的功能。扩展内置用户模型时,请使用“用户”以外的模型名称,例如“客户”或“客户端”。不要将其命名为“用户”,因为这会与内置的用户模型发生冲突。