Skip to content

Commit

Permalink
fix(editor): redirect user to login on "token expired" error
Browse files Browse the repository at this point in the history
In the future, the app should refresh the token instead.

ISSUES CLOSED: #13
  • Loading branch information
EricLambrecht committed Sep 2, 2018
1 parent 779b222 commit 8010c75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/store/editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export default {
commit('setPlaylist', playlist);
dispatch('setStartingTime', { startHour: state.startHour, startMinute: state.startMinute });
} catch (err) {
if (err.message === 'Token expired') {
commit('user/setAccessToken', null, { root: true });
}
commit('setError', err.message);
dispatch('setError', err.message);
}
},
setError({ commit }, errorMessage) {
if (errorMessage === 'Token expired') {
commit('user/setAccessToken', null, { root: true });
}
commit('setError', errorMessage);
},
setStartingTime({ commit, state }, { startHour, startMinute }) {
commit('setStartingTime', { startHour, startMinute });
Expand Down
4 changes: 2 additions & 2 deletions src/store/user/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default {
commit('setAccessToken', null);
}
},
async getPlaylists({ commit, state }) {
async getPlaylists({ commit, dispatch, state }) {
try {
spotifyApi.setAccessToken(state.accessToken);
commit('setPlaylists', await spotifyApi.getUserPlaylists());
} catch (err) {
commit('editor/setError', err.message, { root: true });
dispatch('editor/setError', err.message, { root: true });
}
},
};

0 comments on commit 8010c75

Please sign in to comment.