1
1
/**
2
2
* Container for the standard Topcoder header.
3
3
*/
4
+ /* global location */
5
+ /* eslint-disable no-restricted-globals */
4
6
5
7
import _ from 'lodash' ;
6
8
import headerActions from 'actions/topcoder_header' ;
@@ -10,6 +12,29 @@ import TopcoderHeader from 'components/Header';
10
12
import { connect } from 'react-redux' ;
11
13
import { bindActionCreators } from 'redux' ;
12
14
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
+
13
38
function mapDispatchToProps ( dispatch ) {
14
39
return {
15
40
...bindActionCreators ( headerActions . topcoderHeader , dispatch ) ,
@@ -37,6 +62,8 @@ function mapDispatchToProps(dispatch) {
37
62
}
38
63
39
64
function mapStateToProps ( state ) {
65
+ authCheck ( state . auth . tokenV3 ) ;
66
+
40
67
return {
41
68
...state . topcoderHeader ,
42
69
profile : {
0 commit comments