Skip to content

Commit

Permalink
Fix console error with infinite token update and getting user due to …
Browse files Browse the repository at this point in the history
…asynchronous dispatch.
  • Loading branch information
IrinaMalysheva committed May 26, 2022
1 parent c522cd4 commit fb51a54
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/services/actions/authRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ export const getUser: AppThunk = () => (dispatch) => {
})
.catch((err) => {
if (getCookie('refreshToken')) {
dispatch(updateToken());
dispatch(getUser());
dispatch(updateToken(getUser));
} else {
dispatch(getUserErrorAction())
}
Expand Down Expand Up @@ -360,7 +359,7 @@ export const resetPassword: AppThunk = (passwordValue: string, tokenValue: strin
})
};

export const updateToken: AppThunk = () => (dispatch: AppDispatch) => {
export const updateToken: AppThunk = (afterRefresh: AppThunk) => (dispatch) => {
dispatch(updateTokenRequestAction());
return fetch(API_URL + "/auth/token", {
method: 'POST',
Expand All @@ -377,6 +376,7 @@ export const updateToken: AppThunk = () => (dispatch: AppDispatch) => {
const accessToken = jsonResp.accessToken.split('Bearer ')[1];
setCookie('accessToken', accessToken, { path: '/' });
dispatch(updateTokenSuccessAction());
dispatch(afterRefresh());
}
})
.catch((err) => {
Expand Down

0 comments on commit fb51a54

Please sign in to comment.