mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03: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
@ -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 {
|
||||
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
|
||||
searchParams.set('success', true);
|
||||
res.redirect(`${urlUtils.getSubdir()}${redirectPath}?${searchParams.toString()}`);
|
||||
} catch (err) {
|
||||
logging.warn(err.message);
|
||||
|
||||
const redirectPath = '/';
|
||||
// Do a standard 302 redirect to the homepage, with success=false
|
||||
searchParams.set('success', false);
|
||||
} finally {
|
||||
res.redirect(`${redirectPath}?${searchParams.toString()}`);
|
||||
res.redirect(`${urlUtils.getSubdir()}${redirectPath}?${searchParams.toString()}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user