mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Redirected to custom path on successful signup (#12372)
refs #12366 This implements redirection based on the settings for successful member sign up! - Removes support for redirecting to `req.path` afterwards, this was never used and we now have a more configurable implementation. - Retains redirection to the homepage for unsuccessful sign up (invalid/expired token)
This commit is contained in:
parent
874403d3ae
commit
9ba3e96790
1 changed files with 25 additions and 7 deletions
|
@ -132,20 +132,38 @@ const createSessionFromMagicLink = async function (req, res, next) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// We need to include the subdirectory,
|
|
||||||
// members is already removed from the path by express because it's a mount path
|
|
||||||
let redirectPath = `${urlUtils.getSubdir()}${req.path}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await membersService.ssr.exchangeTokenForSession(req, res);
|
const member = await membersService.ssr.exchangeTokenForSession(req, res);
|
||||||
|
const subscriptions = member && member.stripe && member.stripe.subscriptions || [];
|
||||||
|
|
||||||
|
let redirectPath = '/';
|
||||||
|
const action = req.query.action || req.query['portal-action'];
|
||||||
|
if (action === 'signup') {
|
||||||
|
if (subscriptions.find(sub => ['active', 'trialing'].includes(sub.status))) {
|
||||||
|
redirectPath = settingsCache.get('members_paid_signup_redirect') || '/';
|
||||||
|
} else {
|
||||||
|
redirectPath = settingsCache.get('members_free_signup_redirect') || '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!redirectPath.startsWith('/')) {
|
||||||
|
redirectPath = '/' + redirectPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!redirectPath.endsWith('/')) {
|
||||||
|
redirectPath = redirectPath + '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Do a standard 302 redirect, with success=true
|
// Do a standard 302 redirect, with success=true
|
||||||
searchParams.set('success', true);
|
searchParams.set('success', true);
|
||||||
|
res.redirect(`${urlUtils.getSubdir()}${redirectPath}?${searchParams.toString()}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logging.warn(err.message);
|
logging.warn(err.message);
|
||||||
|
|
||||||
|
const redirectPath = '/';
|
||||||
|
// Do a standard 302 redirect to the homepage, with success=false
|
||||||
searchParams.set('success', false);
|
searchParams.set('success', false);
|
||||||
} finally {
|
res.redirect(`${urlUtils.getSubdir()}${redirectPath}?${searchParams.toString()}`);
|
||||||
res.redirect(`${redirectPath}?${searchParams.toString()}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue