Skip to content

Commit

Permalink
Merge branch 'wookiem-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bartonhammond committed Feb 23, 2016
2 parents 36c59ae + 8518154 commit 3a1e600
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
63 changes: 38 additions & 25 deletions src/reducers/auth/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ export function signupRequest() {
type: SIGNUP_REQUEST
};
}
export function signupSuccess() {
export function signupSuccess(json) {
return {
type: SIGNUP_SUCCESS
type: SIGNUP_SUCCESS,
payload: json
};
}
export function signupFailure(error) {
Expand Down Expand Up @@ -254,18 +255,29 @@ export function signup(username, email, password) {
email: email,
password: password
})
.then((json) => {
saveSessionToken(json)
.then(() => {
dispatch(logoutState());
dispatch(signupSuccess());
});
})
.catch((error) => {
dispatch(signupFailure(error));
});
.then(function (json) {
return saveSessionToken(json)
.then(function () {
dispatch(signupSuccess(
Object.assign({},
{
username: username,
email: email,
objectId: json.objectId,
createdAt: json.createdAt,
sessionToken: json.sessionToken
}
)
));
dispatch(logoutState());
});
})
.catch((error) => {
dispatch(signupFailure(error));
});
};
}

/**
* ## Login actions
*/
Expand All @@ -275,9 +287,10 @@ export function loginRequest() {
};
}

export function loginSuccess() {
export function loginSuccess(json) {
return {
type: LOGIN_SUCCESS
type: LOGIN_SUCCESS,
payload: json
};
}

Expand Down Expand Up @@ -305,19 +318,19 @@ export function login(username, password) {
username: username,
password: password
})
.then((json) => {
saveSessionToken(json)
.then(() => {
dispatch(logoutState());
dispatch(loginSuccess());
});
})
.catch((error) => {
dispatch(loginFailure(error));
});

.then(function (json) {
return saveSessionToken(json)
.then(function () {
dispatch(loginSuccess(json));
dispatch(logoutState());
});
})
.catch((error) => {
dispatch(loginFailure(error));
});
};
}

/**
* ## ResetPassword actions
*/
Expand Down
2 changes: 2 additions & 0 deletions src/reducers/global/globalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
SET_SESSION_TOKEN,

GET_PROFILE_SUCCESS,
SIGNUP_SUCCESS,
LOGIN_SUCCESS,

GET_STATE,
Expand Down Expand Up @@ -48,6 +49,7 @@ export default function globalReducer(state = initialState, action) {
* ```objectId``` which will be needed for some calls to Parse
*/
case GET_PROFILE_SUCCESS:
case SIGNUP_SUCCESS:
case LOGIN_SUCCESS:
return state.set('currentUser',action.payload);

Expand Down

0 comments on commit 3a1e600

Please sign in to comment.