diff --git a/src/api/user/index.js b/src/api/user/index.js index 36661c3ba..f1e627e2b 100644 --- a/src/api/user/index.js +++ b/src/api/user/index.js @@ -68,7 +68,7 @@ export async function refreshTokens(refreshToken) { * @returns {Promise} */ export async function fetchCurrentUser() { - return (await api.callOld(QUERY_CURRENT_USER)).me; + return await api.call(QUERY_CURRENT_USER, {}, undefined, { allowErrors: true }); } /** diff --git a/src/store/modules/user/index.js b/src/store/modules/user/index.js index fb6d306eb..c33f44304 100644 --- a/src/store/modules/user/index.js +++ b/src/store/modules/user/index.js @@ -135,9 +135,22 @@ const actions = { * @param {Function} commit - standard Vuex commit function */ async [FETCH_CURRENT_USER]({ commit }) { - const me = await userApi.fetchCurrentUser(); + const response = await userApi.fetchCurrentUser(); - commit(mutationTypes.SET_CURRENT_USER, me); + if (Array.isArray(response.errors) && response.errors.length) { + const code = response.errors[0].extensions.code; + + /** + * If user is not authenticated, log out + */ + if (code === 'UNAUTHENTICATED') { + commit(RESET_STORE); + + return; + } + } + + commit(mutationTypes.SET_CURRENT_USER, response.data.me); }, /**