Skip to content

Commit

Permalink
Merge pull request #654 from codex-team/master
Browse files Browse the repository at this point in the history
Update prod
  • Loading branch information
neSpecc authored Feb 4, 2025
2 parents 2c18525 + a261649 commit a7b1be8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/api/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export async function refreshTokens(refreshToken) {
/**
* Get current user
*
* @returns {Promise<User>}
* @returns {Promise<APIResponse<{ me: User }>>}
*/
export async function fetchCurrentUser() {
return (await api.callOld(QUERY_CURRENT_USER)).me;
return await api.call(QUERY_CURRENT_USER, {}, undefined, { allowErrors: true });
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/store/modules/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down

0 comments on commit a7b1be8

Please sign in to comment.