Jul 23, 2017 · 1 min read
Great tutorial, I’m loving it.
Wanted to share another way to write the authenticate function (using async/await):
export const authenticate = () => async dispatch => {
dispatch({ type: 'AUTHENTICATION_REQUEST' });
try {
let response = await api.post('/sessions/refresh');
setCurrentUser(dispatch, response);
} catch(e) {
localStorage.removeItem('token');
window.location = '/login';
}
}