Move clearUserId to Auth.duck.js

Clear user ID from the logger in logout thunk instead of the Topbar.

Also call dispatch logging function also as the last action of a thunk
function where possible.
This commit is contained in:
Hannu Lyytikainen 2017-10-03 16:13:23 +03:00
parent de5ec59119
commit 2cfd3deaa1
6 changed files with 14 additions and 14 deletions

View file

@ -9,7 +9,6 @@ import { withFlattenedRoutes, withViewport } from '../../util/contextHelpers';
import { parse, stringify } from '../../util/urlHelpers';
import { createResourceLocatorString, pathByRouteName } from '../../util/routes';
import * as propTypes from '../../util/propTypes';
import { clearUserId } from '../../util/log';
import {
Button,
IconEmailAttention,
@ -146,9 +145,6 @@ class TopbarComponent extends Component {
window.location = path;
}
// clear user id from logger
clearUserId();
// TODO: show flash message
console.log('logged out'); // eslint-disable-line
});

View file

@ -119,8 +119,8 @@ export const initiateOrder = params =>
return orderId;
})
.catch(e => {
dispatch(logError(e, 'initiate-order-failed'));
dispatch(initiateOrderError(e));
dispatch(logError(e, 'initiate-order-failed'));
throw e;
});
};

View file

@ -144,13 +144,13 @@ export const acceptSale = id =>
return response;
})
.catch(e => {
dispatch(acceptSaleError(e));
dispatch(
logError(e, 'accept-sale-failed', {
txId: id,
transition: propTypes.TX_TRANSITION_ACCEPT,
})
);
dispatch(acceptSaleError(e));
throw e;
});
};
@ -171,13 +171,13 @@ export const rejectSale = id =>
return response;
})
.catch(e => {
dispatch(rejectSaleError(e));
dispatch(
logError(e, 'redect-sale-failed', {
txId: id,
transition: propTypes.TX_TRANSITION_REJECT,
})
);
dispatch(rejectSaleError(e));
throw e;
});
};

View file

@ -1,5 +1,6 @@
import { clearCurrentUser, fetchCurrentUser } from './user.duck';
import { logError } from './log.duck';
import * as log from '../util/log';
const authenticated = authInfo => authInfo.grantType === 'refresh_token';
@ -157,7 +158,10 @@ export const logout = () =>
.logout()
.then(() => dispatch(clearCurrentUser()))
.then(() => dispatch(logoutSuccess()))
.then(() => dispatch(userLogout()))
.then(() => {
dispatch(userLogout());
log.clearUserId();
})
.catch(e => dispatch(logoutError(e)));
};
@ -176,7 +180,7 @@ export const signup = params =>
.then(() => dispatch(signupSuccess()))
.then(() => dispatch(login(email, password)))
.catch(e => {
dispatch(logError(e, 'signup-failed'));
dispatch(signupError(e));
dispatch(logError(e, 'signup-failed'));
});
};

View file

@ -1,6 +1,6 @@
/**
* A utility duck file that can be used to pass
* error data to a logger.
* A utility duck file that allows logger to be
* used with Redux's `dispatch` function.
*/
import * as log from '../util/log';

View file

@ -1,8 +1,8 @@
import { authInfo } from './Auth.duck';
import { updatedEntities, denormalisedEntities } from '../util/data';
import { TX_TRANSITION_PREAUTHORIZE } from '../util/propTypes';
import { setUserId } from '../util/log';
import { logError } from './log.duck';
import * as log from '../util/log';
// ================ Action types ================ //
@ -340,7 +340,7 @@ export const fetchCurrentUser = () =>
const denormalised = denormalisedEntities(entities, 'current-user', [currentUserId]);
const currentUser = denormalised[0];
// set current user id to the logger
setUserId(currentUser.id.uuid);
log.setUserId(currentUser.id.uuid);
dispatch(currentUserShowSuccess(currentUser));
return currentUser;
})
@ -379,8 +379,8 @@ export const createStripeAccount = payoutDetails =>
dispatch(stripeAccountCreateSuccess(accountResponse));
})
.catch(e => {
dispatch(logError(e, 'create-stripe-account-failed'));
dispatch(stripeAccountCreateError(e));
dispatch(logError(e, 'create-stripe-account-failed'));
throw e;
});
};