0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

Exposed getMagicLink method (#123)

refs https://github.com/TryGhost/Ghost/pull/11573

- Adds `getMagicLink` method to members-api which can be used to generate a signin link for the member
This commit is contained in:
Naz 2020-02-06 17:08:39 +08:00 committed by GitHub
parent 133d1ece06
commit 2a51a478fc
2 changed files with 24 additions and 0 deletions

View file

@ -107,6 +107,25 @@ MagicLink.prototype.sendMagicLink = async function sendMagicLink(options) {
return {token, info};
};
/**
* getMagicLink
*
* @param {object} options
* @param {object} options.subject - The subject to associate with the magic link (user id, or email)
* @param {string=} [options.type='signin'] - The type to be passed to the url and content generator functions
* @returns {string} - signin URL
*/
MagicLink.prototype.getMagicLink = function getMagicLink(options) {
const token = jwt.sign({}, this.secret, {
algorithm: 'HS256',
subject: options.subject,
expiresIn: '10m'
});
const type = options.type || 'signin';
return this.getSigninURL(token, type);
};
/**
* getUserFromToken

View file

@ -85,6 +85,10 @@ module.exports = function MembersApi({
}
}
function getMagicLink(email) {
return magicLinkService.getMagicLink({email, subject: email, type: 'signin'});
}
const users = Users({
stripe,
memberModel
@ -329,6 +333,7 @@ module.exports = function MembersApi({
getPublicConfig,
bus,
sendEmailWithMagicLink,
getMagicLink,
members: users
};
};