@@ -13,7 +13,8 @@ import React from 'react';
1313import { Route , Switch , Redirect } from 'react-router-dom' ;
1414import Viewport from 'components/Contentful/Viewport' ;
1515import PasswordScreen from 'components/Contentful/PasswordScreen' ;
16- import { isomorphy } from 'topcoder-react-utils' ;
16+ import { isomorphy , config } from 'topcoder-react-utils' ;
17+ import cookies from 'browser-cookies' ;
1718import { removeTrailingSlash } from 'utils/url' ;
1819
1920// Concatenates a base and segment and handles optional trailing slashes
@@ -173,6 +174,14 @@ export default function ContentfulRoute(props) {
173174 // eslint-disable-next-line no-restricted-globals
174175 const currentPathname = typeof location === 'undefined' ? '' : removeTrailingSlash ( location . pathname ) ;
175176 const redirectToUrl = _ . trim ( fields . redirectToUrl ) ;
177+ const requireLogin = fields . protected ;
178+ const loggedIn = isomorphy . isClientSide ( ) && cookies . get ( 'tcjwt' ) !== null ;
179+ if ( requireLogin && ! loggedIn ) {
180+ // route is protected by TC Login
181+ // send to login/register with proper retUrl set
182+ const authUrl = config . URL . AUTH ;
183+ return < RedirectWithStatus status = { 401 } from = { url } to = { `${ authUrl } ?retUrl=${ encodeURIComponent ( config . URL . BASE + url ) } ` } /> ;
184+ }
176185 return redirectToUrl && currentPathname === url ? (
177186 < RedirectWithStatus status = { 301 } from = { url } to = { redirectToUrl } />
178187 ) : (
0 commit comments