diff --git a/src/reducers/auth/authActions.js b/src/reducers/auth/authActions.js index 880dbff8..3dde494c 100644 --- a/src/reducers/auth/authActions.js +++ b/src/reducers/auth/authActions.js @@ -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) { @@ -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 */ @@ -275,9 +287,10 @@ export function loginRequest() { }; } -export function loginSuccess() { +export function loginSuccess(json) { return { - type: LOGIN_SUCCESS + type: LOGIN_SUCCESS, + payload: json }; } @@ -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 */ diff --git a/src/reducers/global/globalReducer.js b/src/reducers/global/globalReducer.js index 3486cfe4..a81dbb83 100644 --- a/src/reducers/global/globalReducer.js +++ b/src/reducers/global/globalReducer.js @@ -14,6 +14,7 @@ const { SET_SESSION_TOKEN, GET_PROFILE_SUCCESS, + SIGNUP_SUCCESS, LOGIN_SUCCESS, GET_STATE, @@ -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);