diff --git a/ghost/members-api/index.js b/ghost/members-api/index.js index 5d4bcf9028..31d3596b0e 100644 --- a/ghost/members-api/index.js +++ b/ghost/members-api/index.js @@ -54,15 +54,6 @@ module.exports = function MembersApi({ } } - let users = Users({ - stripe, - createMember, - getMember, - updateMember, - deleteMember, - listMembers - }); - const magicLinkService = new MagicLink({ transporter, publicKey, @@ -73,6 +64,17 @@ module.exports = function MembersApi({ async function sendEmailWithMagicLink(email){ return magicLinkService.sendMagicLink({email, user: {email}}); } + + const users = Users({ + sendEmailWithMagicLink, + stripe, + createMember, + getMember, + updateMember, + deleteMember, + listMembers + }); + async function getMemberDataFromMagicLinkToken(token){ const user = await magicLinkService.getUserFromToken(token); const email = user && user.email; diff --git a/ghost/members-api/lib/users.js b/ghost/members-api/lib/users.js index fe2ff498e0..799477a92e 100644 --- a/ghost/members-api/lib/users.js +++ b/ghost/members-api/lib/users.js @@ -1,4 +1,5 @@ module.exports = function ({ + sendEmailWithMagicLink, stripe, createMember, getMember, @@ -53,7 +54,11 @@ module.exports = function ({ } async function create(data, options) { - return createMember(data, options); + const member = await createMember(data); + if (options.sendEmail) { + await sendEmailWithMagicLink(member.email, options.emailType); + } + return member; } return {