@@ -10,7 +10,7 @@ import React from 'react';
10
10
import { connect } from 'react-redux' ;
11
11
import { browserHistory } from 'react-router' ;
12
12
import * as actionCreators from './../actions' ;
13
- import { refreshToken } from './../helpers/sdk' ;
13
+ import { refreshToken , getUserData } from './../helpers/sdk' ;
14
14
15
15
/**
16
16
* class AuthRequiredContainer
@@ -30,6 +30,12 @@ class AuthRequiredContainer extends React.Component {
30
30
this . props . refreshToken ( this . props . clientAccessToken , this . props . refreshTokenStr ) ;
31
31
}
32
32
}
33
+
34
+ // Check if user data exists
35
+ if ( this . props . user . id == undefined ) {
36
+ // Fetch user data
37
+ this . props . getUserData ( this . props . accessToken ) ;
38
+ }
33
39
}
34
40
35
41
render ( ) {
@@ -42,7 +48,9 @@ const mapStateToProps = (state) => {
42
48
isAuthenticated : state . auth . isAuthenticated ,
43
49
tokenExpiresAt : state . auth . tokenExpiresAt ,
44
50
clientAccessToken : state . auth . clientAccessToken ,
45
- refreshTokenStr : state . auth . refreshToken
51
+ accessToken : state . auth . accessToken ,
52
+ refreshTokenStr : state . auth . refreshToken ,
53
+ user : state . user
46
54
}
47
55
} ;
48
56
@@ -55,6 +63,14 @@ const mapDispatchToProps = (dispatch) => {
55
63
console . log ( 'Failed refreshing access token. Please try again' ) ;
56
64
console . log ( error ) ;
57
65
} ) ;
66
+ } ,
67
+ getUserData : ( accessToken ) => {
68
+ getUserData ( accessToken ) . then ( function ( response ) {
69
+ dispatch ( actionCreators . saveUserData ( response ) ) ;
70
+ } ) . catch ( function ( error ) {
71
+ console . log ( 'Failed getting user data' ) ;
72
+ console . log ( error ) ;
73
+ } ) ;
58
74
}
59
75
} ;
60
76
} ;
0 commit comments