Skip to content

Commit 7a978d1

Browse files
authored
Merge pull request #67 from SourceCodeOER/jy95-patch-1
feat: Force refresh token with we got a 401 (WIP)
2 parents 89161fe + 1928678 commit 7a978d1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

plugins/axios.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const axios: Plugin = ({$axios, redirect, $auth, app}) => {
1616
return response
1717
},
1818
async (error) => {
19-
if (error.response.status === 401 && app.router && app.router.currentRoute.path !== '/login') {
20-
21-
if($auth.loggedIn) {
22-
await $auth.logout();
23-
}
24-
25-
redirect(401, "/login");
19+
const status = parseInt(error.response && error.response.status);
20+
const shouldRefresh = [401, 403].includes(status);
21+
if (shouldRefresh) {
22+
await $auth.logout();
23+
}
24+
if (shouldRefresh && app.router && app.router.currentRoute.path !== '/login') {
25+
redirect(status, "/login");
2626
} else {
2727
return Promise.reject(error);
2828
}

0 commit comments

Comments
 (0)