Skip to content

Instantly share code, notes, and snippets.

@zbarbuto
Created December 15, 2017 05:21
Show Gist options
  • Save zbarbuto/3b8daca7ef43731a3d040c26ed8b80e5 to your computer and use it in GitHub Desktop.
Save zbarbuto/3b8daca7ef43731a3d040c26ed8b80e5 to your computer and use it in GitHub Desktop.
const loopback = require('loopback');
module.exports = function(app) {
app.model(
loopback.Model.extend(
'LoginCredentials',
{
id: false,
username: 'string',
password: 'string'
},
{ forceId: false, idInjection: false }
)
);
updateLoginMethod(app);
};
function updateLoginMethod(app) {
const login = app.models.User.sharedClass
.methods()
.find(item => item.name === 'login');
Object.assign(login, {
accepts: [
{
arg: 'credentials',
type: 'LoginCredentials',
required: true,
http: { source: 'body' }
}
],
returns: [{ type: 'AccessToken', root: true }]
});
app.emit('modelRemoted');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment