Andrew Mager ♫
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';
}
}
    Andrew Mager ♫

    Written by

    Full Stack Engineer at @Postmates. Blogger turned coder. Music charms the soul. On Twitter: @mager.