fix: redirect correctly in development (#40594)
* fix: redirect correctly in development * fix: prevent // appearing in path * refactor: remove old comments * fix: remove trailing slash for redirection
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
49b1c29f6b
commit
77022b8a56
@ -86,9 +86,12 @@ export const devSaveResponseAuthCookies = () => {
|
|||||||
export const devLoginRedirect = () => {
|
export const devLoginRedirect = () => {
|
||||||
return (req, res) => {
|
return (req, res) => {
|
||||||
// this mirrors the production approach, but without any validation
|
// this mirrors the production approach, but without any validation
|
||||||
let { returnTo, origin, pathPrefix } = getRedirectParams(req);
|
let { returnTo, origin, pathPrefix } = getRedirectParams(
|
||||||
|
req,
|
||||||
|
params => params
|
||||||
|
);
|
||||||
returnTo += isRootPath(getRedirectBase(origin, pathPrefix), returnTo)
|
returnTo += isRootPath(getRedirectBase(origin, pathPrefix), returnTo)
|
||||||
? '/learn'
|
? 'learn'
|
||||||
: '';
|
: '';
|
||||||
return res.redirect(returnTo);
|
return res.redirect(returnTo);
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,6 @@ function getReturnTo(encryptedParams, secret, _homeLocation = homeLocation) {
|
|||||||
return normalizeParams(params, _homeLocation);
|
return normalizeParams(params, _homeLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tests!
|
|
||||||
function normalizeParams(
|
function normalizeParams(
|
||||||
{ returnTo, origin, pathPrefix },
|
{ returnTo, origin, pathPrefix },
|
||||||
_homeLocation = homeLocation
|
_homeLocation = homeLocation
|
||||||
@ -59,9 +58,6 @@ function getRedirectBase(origin, pathPrefix) {
|
|||||||
return `${origin}${redirectPathSegment}`;
|
return `${origin}${redirectPathSegment}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this might be cleaner if we just use a URL for returnTo (call it
|
|
||||||
// returnURL for clarity) rather than pulling out origin and returning it
|
|
||||||
// separately
|
|
||||||
function getRedirectParams(req, _normalizeParams = normalizeParams) {
|
function getRedirectParams(req, _normalizeParams = normalizeParams) {
|
||||||
const url = req.header('Referer');
|
const url = req.header('Referer');
|
||||||
// since we do not always redirect the user back to the page they were on
|
// since we do not always redirect the user back to the page they were on
|
||||||
|
Reference in New Issue
Block a user