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

Added alpha version of auto-login for Members

refs https://github.com/TryGhost/Team/issues/1067

This is the MVP for auto-login of Members, it does not support custom
redirects, and will always just redirect to the same place that the
signin & signup links do. Behind a feature flag whilst we iron out the
functionality.
This commit is contained in:
Fabien O'Carroll 2021-11-03 10:57:28 +02:00
parent 2c294be428
commit 81868c1850

View file

@ -193,12 +193,29 @@ module.exports = class RouterController {
const member = email ? await this._memberRepository.get({email}, {withRelated: ['stripeCustomers', 'products']}) : null;
let successUrl = req.body.successUrl || this._config.checkoutSuccessUrl;
let cancelUrl = req.body.cancelUrl || this._config.checkoutCancelUrl;
if (this.labsService.isSet('membersAutoLogin')) {
if (!member && req.body.customerEmail) {
const memberExistsForCustomer = await this._memberRepository.get({email: req.body.customerEmail});
if (!memberExistsForCustomer) {
successUrl = await this._magicLinkService.getMagicLink({
tokenData: {
email: req.body.customerEmail
},
type: 'signup'
});
}
}
}
if (!member) {
const customer = null;
const session = await this._stripeAPIService.createCheckoutSession(priceId, customer, {
coupon: couponId,
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
successUrl,
cancelUrl,
customerEmail: req.body.customerEmail,
metadata: metadata
});
@ -242,8 +259,8 @@ module.exports = class RouterController {
try {
const session = await this._stripeAPIService.createCheckoutSession(priceId, stripeCustomer, {
coupon: couponId,
successUrl: req.body.successUrl || this._config.checkoutSuccessUrl,
cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl,
successUrl,
cancelUrl,
metadata: metadata
});
const publicKey = this._stripeAPIService.getPublicKey();