Skip to content

Instantly share code, notes, and snippets.

@SippieCup
Created July 25, 2017 11:30
Show Gist options
  • Save SippieCup/9560a4ee3b89ca882dd2b22f941218e7 to your computer and use it in GitHub Desktop.
Save SippieCup/9560a4ee3b89ca882dd2b22f941218e7 to your computer and use it in GitHub Desktop.
Loopback MultiUser Example
module.exports = function (ExtendedUserModel) {
ExtendedUserModel.afterRemote('create', function(context, user, next) {
createDriver(user)
.then(createCustomer(user)
.then(sendVerificationEmail(user)
.then( () => next())));
function createDriver(user) {
if (user.realm==="driver") {
return user.driver.create({Licensed: true});
} else {
return Promise.resolve();
}
}
function createCustomer(user) {
if (user.realm==="customer") {
return user.customer.create({hasMoney: true});
} else {
return Promise.resolve();
}
}
function sendVerificationEmail(user) {
var options = {
type: 'email',
to: user.email,
from: 'noreply@uberclone.com',
subject: 'Thanks for registering.',
user: user
};
return user.verify(options);
}
)};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment