fix: sso redirect on /login & /api/login

This commit is contained in:
Barış Soner Uşaklı
2020-12-03 10:29:18 -05:00
parent c7f2640a18
commit 5d00b0895b
3 changed files with 26 additions and 11 deletions

View File

@@ -145,11 +145,20 @@ helpers.notAllowed = async function (req, res, error) {
};
helpers.redirect = function (res, url, permanent) {
if (res.locals.isAPI) {
res.set('X-Redirect', encodeURI(url)).status(200).json(encodeURI(url));
let redirectUrl;
// this is used by sso plugins to redirect to the auth route
if (url.hasOwnProperty('external')) {
url.external = encodeURI(url.external);
redirectUrl = url.external;
} else {
const redirectUrl = url.startsWith('http://') || url.startsWith('https://') ?
url : relative_path + url;
url = encodeURI(url);
redirectUrl = url;
}
if (res.locals.isAPI) {
res.set('X-Redirect', redirectUrl).status(200).json(url);
} else {
redirectUrl = redirectUrl.startsWith('http://') || redirectUrl.startsWith('https://') ?
redirectUrl : relative_path + redirectUrl;
res.redirect(permanent ? 308 : 307, encodeURI(redirectUrl));
}
};