Skip to content

Commit

Permalink
Fix refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
boobo94 committed Aug 24, 2022
1 parent 8a7f4d6 commit 314aae7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions admin/src/services/axiosService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export default function axiosErrorInterceptor(store, router) {
if (err.config && !err.config.__isRetryRequest && err.response.status === 401) {
// when auth token is expired refresh it
if (err.response.data.error.code === 3) {
store.dispatch('authModule/refreshToken')
return store.dispatch('authModule/refreshToken')
.then(async () => {
// rewrite the current Authorization header
axios.defaults.headers.Authorization = `Bearer ${store.state.auth.token}`;
// rewrite the current Authorization header
axios.defaults.headers.authorization = `Bearer ${store.state.authModule.token}`;
// eslint-disable-next-line no-param-reassign
err.config.headers.Authorization = axios.defaults.headers.Authorization;
err.config.headers.authorization = axios.defaults.headers.authorization;

return axios(err.config)
.then((response) => resolve(response))
Expand Down
2 changes: 1 addition & 1 deletion api/src/routers/admin/v1/auth/refresh-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async (req, res) => {
}, admin.id);

return res.status(StatusCodes.OK).send({
token: GenerateJWT(admin.id),
token: GenerateJWT(admin.id, admin.restaurantId),
refreshToken: newRefreshToken,
restaurantId: admin.restaurantId,
});
Expand Down

0 comments on commit 314aae7

Please sign in to comment.