Skip to content

Commit aae41a1

Browse files
committed
Additional fix for the social login case
1 parent 6575e74 commit aae41a1

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/routes/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ import ProviderDetailsRoute from './ProviderDetails';
2525
import ResetPasswordRoute from './ResetPassword';
2626
import {defaultAuth0Service} from '../services/AuthService';
2727

28+
import {onSocialLoginSuccessAction} from 'store/modules/global';
29+
2830
export const createRoutes = (store) => ({
2931
path: '/',
3032
name: 'CoreLayout',
3133
indexRoute: {
3234
onEnter: (nextState, replace, cb) => {
3335
// parse the hash if present
3436
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+
});
3841
} else {
3942
replace('/dashboard');
4043
cb();

src/services/AuthService.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,27 @@ class AuthService {
6464
if (authResult && authResult.idToken) {
6565
_self.setToken(authResult.idToken);
6666
// get social profile
67-
_self.getProfile((error, profile) => {
68-
if (error) {
69-
// remove the id token
70-
_self.removeToken();
71-
throw error;
72-
} else {
73-
userApi.registerSocialUser(profile.name, profile.email, _self.getToken()).then(
74-
(authResult) => {
75-
localStorage.setItem('userInfo', JSON.stringify(authResult));
76-
}).catch((reason) => {
67+
return new Promise((resolve) => {
68+
_self.getProfile((error, profile) => {
69+
if (error) {
7770
// remove the id token
78-
_self.removeToken();
79-
throw reason;
80-
});
81-
}
71+
_self.removeToken();
72+
throw error;
73+
} else {
74+
return userApi.registerSocialUser(profile.name, profile.email, _self.getToken()).then(
75+
(authResult2) => {
76+
localStorage.setItem('userInfo', JSON.stringify(authResult2));
77+
resolve(authResult2);
78+
}).catch((reason) => {
79+
// remove the id token
80+
_self.removeToken();
81+
throw reason;
82+
});
83+
}
84+
});
8285
});
8386
}
87+
return Promise.reject(new Error('Social login failure'));
8488
}
8589

8690
/**

src/store/modules/global.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export const loginAction = (data) => (dispatch) => {
7272
});
7373
};
7474

75+
export const onSocialLoginSuccessAction = () => (dispatch) => {
76+
dispatch({type: LOGIN_ACTION_SUCCESS});
77+
browserHistory.push(LOGIN_REDIRECT[loadUserInfo().user.role]);
78+
};
79+
7580
export const logoutAction = () => (dispatch) => {
7681
browserHistory.push('/home');
7782
dispatch({

0 commit comments

Comments
 (0)