Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I override builtin login method in Loopback?

I've created a new User model, based on builtin one. I'm trying this:

module.exports = function(TiUser) {
  TiUser.on('dataSourceAttached', function(obj) {
    var login = TiUser.login;
    TiUser.login = function(credentials, include, cb) {
      var result = login.apply(this, credentials);

      // Do my stuff
      cb(null, my_data);
    };
  });
};

But I can't get it working... What is wrong? or how could this be done right?

Thanks

like image 414
F.D.F. Avatar asked Sep 10 '15 16:09

F.D.F.


1 Answers

You may want to consider adding an afterRemote() hook to login(). Now you can achieve to add role( using Role model ) to user. For example:

TiUser.afterRemote('login', function(ctx, next) {

    //add role to the user.

    next();
});
like image 179
xangy Avatar answered Nov 29 '22 11:11

xangy