feat(api): allow redirects with a returnTo param (#40161)

This commit is contained in:
Oliver Eyton-Williams
2020-11-07 09:05:25 +01:00
committed by GitHub
parent 8fd00afd9c
commit b2e2f33cf1
8 changed files with 111 additions and 76 deletions

View File

@@ -5,7 +5,7 @@ import { createSelector } from 'reselect';
import { Grid, Button } from '@freecodecamp/react-bootstrap';
import Helmet from 'react-helmet';
import { apiLocation } from '../../config/env.json';
import { apiLocation, homeLocation } from '../../config/env.json';
import {
signInLoadingSelector,
userSelector,
@@ -167,7 +167,7 @@ export function ShowSettings(props) {
}
if (!isSignedIn) {
navigate(`${apiLocation}/signin?returnTo=settings`);
navigate(`${apiLocation}/signin?returnTo=${homeLocation}/settings`);
return <Loader fullScreen={true} />;
}

View File

@@ -1,7 +1,7 @@
/* global jest, expect */
import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow';
import { apiLocation } from '../../config/env.json';
import { apiLocation, homeLocation } from '../../config/env.json';
import { ShowSettings } from './ShowSettings';
@@ -23,7 +23,7 @@ describe('<ShowSettings />', () => {
shallow.render(<ShowSettings {...loggedOutProps} />);
expect(navigate).toHaveBeenCalledTimes(1);
expect(navigate).toHaveBeenCalledWith(
`${apiLocation}/signin?returnTo=settings`
`${apiLocation}/signin?returnTo=${homeLocation}/settings`
);
const result = shallow.getRenderOutput();
// Renders Loader rather than ShowSettings