Skip to content

Commit d8f1fc9

Browse files
#4140: Added check if token expired in Header
1 parent 9472329 commit d8f1fc9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/shared/containers/TopcoderHeader.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Container for the standard Topcoder header.
33
*/
4+
/* global location */
5+
/* eslint-disable no-restricted-globals */
46

57
import _ from 'lodash';
68
import headerActions from 'actions/topcoder_header';
@@ -10,6 +12,29 @@ import TopcoderHeader from 'components/Header';
1012
import { connect } from 'react-redux';
1113
import { bindActionCreators } from 'redux';
1214

15+
import { isTokenExpired } from 'tc-accounts';
16+
import { config } from 'topcoder-react-utils';
17+
18+
/**
19+
* Does nothing if a valid TC API v3 token is passed in; otherwise redirects
20+
* user to the TC auth page, with proper return URL.
21+
* @param {String} tokenV3
22+
* @return {Boolean} `true` if the user is authenticated; `false` otherwise.
23+
*/
24+
function authCheck(tokenV3) {
25+
if (tokenV3 && !isTokenExpired(tokenV3)) return true;
26+
27+
/* This implements front-end redirection. Once the server-side rendering of
28+
* the Dashboard is in place, this should be updated to work for the server
29+
* side rendering as well. */
30+
let url = `retUrl=${encodeURIComponent(location.href)}`;
31+
url = `${config.URL.AUTH}/member?${url}&utm_source=community-app-main`;
32+
location.href = url;
33+
34+
_.noop(this);
35+
return false;
36+
}
37+
1338
function mapDispatchToProps(dispatch) {
1439
return {
1540
...bindActionCreators(headerActions.topcoderHeader, dispatch),
@@ -37,6 +62,8 @@ function mapDispatchToProps(dispatch) {
3762
}
3863

3964
function mapStateToProps(state) {
65+
authCheck(state.auth.tokenV3);
66+
4067
return {
4168
...state.topcoderHeader,
4269
profile: {

0 commit comments

Comments
 (0)