Skip to content

Commit

Permalink
Merge pull request #12 from IrinaMalysheva/feature/improvement-1.0
Browse files Browse the repository at this point in the history
Fix console error with infinite token update and getting user
  • Loading branch information
IrinaMalysheva authored May 26, 2022
2 parents c522cd4 + fb51a54 commit f85cae4
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 f85cae4

Please sign in to comment.