File tree Expand file tree Collapse file tree 3 files changed +29
-18
lines changed Expand file tree Collapse file tree 3 files changed +29
-18
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,19 @@ import ProviderDetailsRoute from './ProviderDetails';
25
25
import ResetPasswordRoute from './ResetPassword' ;
26
26
import { defaultAuth0Service } from '../services/AuthService' ;
27
27
28
+ import { onSocialLoginSuccessAction } from 'store/modules/global' ;
29
+
28
30
export const createRoutes = ( store ) => ( {
29
31
path : '/' ,
30
32
name : 'CoreLayout' ,
31
33
indexRoute : {
32
34
onEnter : ( nextState , replace , cb ) => {
33
35
// parse the hash if present
34
36
if ( nextState . location . hash ) {
35
- defaultAuth0Service . parseHash ( nextState . location . hash ) ;
36
- replace ( '/dashboard' ) ;
37
- cb ( ) ;
37
+ defaultAuth0Service . parseHash ( nextState . location . hash ) . then ( ( ) => {
38
+ store . dispatch ( onSocialLoginSuccessAction ( ) ) ;
39
+ cb ( ) ;
40
+ } ) ;
38
41
} else {
39
42
replace ( '/dashboard' ) ;
40
43
cb ( ) ;
Original file line number Diff line number Diff line change @@ -61,24 +61,27 @@ class AuthService {
61
61
const authResult = _self . auth0 . parseHash ( hash ) ;
62
62
if ( authResult && authResult . idToken ) {
63
63
_self . setToken ( authResult . idToken ) ;
64
- // get social profile
65
- _self . getProfile ( ( error , profile ) => {
66
- if ( error ) {
67
- // remove the id token
68
- _self . removeToken ( ) ;
69
- throw error ;
70
- } else {
71
- userApi . registerSocialUser ( profile . name , profile . email , _self . getToken ( ) ) . then (
72
- ( authRes ) => {
73
- localStorage . setItem ( 'userInfo' , JSON . stringify ( authRes ) ) ;
74
- } ) . catch ( ( reason ) => {
64
+ return new Promise ( ( resolve ) => {
65
+ _self . getProfile ( ( error , profile ) => {
66
+ if ( error ) {
75
67
// remove the id token
76
- _self . removeToken ( ) ;
77
- throw reason ;
78
- } ) ;
79
- }
68
+ _self . removeToken ( ) ;
69
+ throw error ;
70
+ } else {
71
+ return userApi . registerSocialUser ( profile . name , profile . email , _self . getToken ( ) ) . then (
72
+ ( authResult2 ) => {
73
+ localStorage . setItem ( 'userInfo' , JSON . stringify ( authResult2 ) ) ;
74
+ resolve ( authResult2 ) ;
75
+ } ) . catch ( ( reason ) => {
76
+ // remove the id token
77
+ _self . removeToken ( ) ;
78
+ throw reason ;
79
+ } ) ;
80
+ }
81
+ } ) ;
80
82
} ) ;
81
83
}
84
+ return Promise . reject ( new Error ( 'Social login failure' ) ) ;
82
85
}
83
86
84
87
/**
Original file line number Diff line number Diff line change @@ -72,6 +72,11 @@ export const loginAction = (data) => (dispatch) => {
72
72
} ) ;
73
73
} ;
74
74
75
+ export const onSocialLoginSuccessAction = ( ) => ( dispatch ) => {
76
+ dispatch ( { type : LOGIN_ACTION_SUCCESS } ) ;
77
+ browserHistory . push ( LOGIN_REDIRECT [ loadUserInfo ( ) . user . role ] ) ;
78
+ } ;
79
+
75
80
export const logoutAction = ( ) => ( dispatch ) => {
76
81
browserHistory . push ( '/home' ) ;
77
82
dispatch ( {
You can’t perform that action at this time.
0 commit comments