fix(api): only use homeLocation as a fallback (#40517)

This commit is contained in:
Oliver Eyton-Williams
2020-12-30 20:10:38 +01:00
committed by Mrugesh Mohapatra
parent 03fa21a565
commit a076547d43
22 changed files with 207 additions and 600 deletions

View File

@ -4,19 +4,19 @@ import { pick } from 'lodash';
import { Observable } from 'rx';
import { body } from 'express-validator';
import { homeLocation } from '../../../config/env';
import {
getProgress,
normaliseUserFields,
userPropsForSession
} from '../utils/publicUserProps';
import { fixCompletedChallengeItem } from '../../common/utils';
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
import { ifNoUser401, ifNoUserRedirectHome } from '../utils/middleware';
import { removeCookies } from '../utils/getSetAccessToken';
import { trimTags } from '../utils/validators';
import { getRedirectParams } from '../utils/redirection';
const log = debugFactory('fcc:boot:user');
const sendNonUserToHome = ifNoUserRedirectTo(homeLocation);
const sendNonUserToHome = ifNoUserRedirectHome();
function bootUser(app) {
const api = app.loopback.Router();
@ -100,7 +100,7 @@ function getAccount(req, res) {
function getUnlinkSocial(req, res, next) {
const { user } = req;
const { username } = user;
const { origin } = getRedirectParams(req);
let social = req.params.social;
if (!social) {
req.flash('danger', 'No social account found');
@ -151,7 +151,7 @@ function getUnlinkSocial(req, res, next) {
log(`${social} has been unlinked successfully`);
req.flash('info', `You've successfully unlinked your ${social}.`);
return res.redirectWithFlash(`${homeLocation}/${username}`);
return res.redirectWithFlash(`${origin}/${username}`);
});
});
});
@ -209,7 +209,7 @@ function createPostReportUserProfile(app) {
return function postReportUserProfile(req, res, next) {
const { user } = req;
const { username, reportDescription: report } = req.body;
const { origin } = getRedirectParams(req);
log(username);
log(report);
@ -241,7 +241,7 @@ function createPostReportUserProfile(app) {
},
err => {
if (err) {
err.redirectTo = `${homeLocation}/${username}`;
err.redirectTo = `${origin}/${username}`;
return next(err);
}