Skip to content

Commit 9be60ce

Browse files
authored
Merge branch 'dev' into dev
2 parents 535807a + 41be62f commit 9be60ce

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,27 @@ class AuthService {
6161
const authResult = _self.auth0.parseHash(hash);
6262
if (authResult && authResult.idToken) {
6363
_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) {
7567
// 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+
});
8082
});
8183
}
84+
return Promise.reject(new Error('Social login failure'));
8285
}
8386

8487
/**

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)