Reputation: 2489
I'd like to extend the user login POST method in loopback.
So far I have extended the base user class to roll out my own, however how do I add functionality to a particular endpoint?
Upvotes: 0
Views: 67
Reputation: 2489
In this example I've created a new model called "UserAuth2" which extended the existing User model provided by LoopbackJS. I've created the model using the slc loopback:model
tool.
In order to extend a function in Loopback use the following code within your model's JS file :
module.exports = function(UserAuth2) {
// Get reference to endpoint
var previousImplementation = UserAuth2.login;
// Create new implementation of endpoint
UserAuth2.login = function(){
//Get existing implementation
/*** arguments is an array of existing arguments that the login
function takes***/
previousImplementation.apply(this, arguments);
//Extend the method and do something else here
console.log("New functionality");
}
}
Upvotes: 1