Added name from magic link token to member creation

refs https://github.com/TryGhost/members.js/issues/26

- Allows magic link tokens to pass member name on signup
- Uses member name from magic link token to assign member name during creation
This commit is contained in:
Rish 2020-05-20 14:33:15 +05:30
parent 01de256cc4
commit d5d2cc5137

View File

@ -96,8 +96,7 @@ module.exports = function MembersApi({
async function getMemberDataFromMagicLinkToken(token) {
const email = await magicLinkService.getUserFromToken(token);
const {labels = [], ip} = await magicLinkService.getPayloadFromToken(token);
const {labels = [], ip, name = ''} = await magicLinkService.getPayloadFromToken(token);
if (!email) {
return null;
}
@ -126,7 +125,7 @@ module.exports = function MembersApi({
return member;
}
await users.create({email, labels, geolocation});
await users.create({name, email, labels, geolocation});
return getMemberIdentityData(email);
}
async function getMemberIdentityData(email){
@ -165,9 +164,7 @@ module.exports = function MembersApi({
await sendEmailWithMagicLink({email, requestedType: emailType, payload});
}
} else {
if (body.labels) {
payload.labels = body.labels;
}
Object.assign(payload, _.pick(body, ['labels', 'name']));
await sendEmailWithMagicLink({email, requestedType: emailType, payload});
}
res.writeHead(201);