Skip to content

Commit a0cca9b

Browse files
committed
fix(Plugin): use app.router instead of router object (axios)
1 parent 1ffa229 commit a0cca9b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

plugins/axios.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import qs from 'qs'
22
import {Plugin} from '@nuxt/types'
33

4-
const axios: Plugin = ({$axios, redirect, $auth, route}) => {
4+
const axios: Plugin = ({$axios, redirect, $auth, app}) => {
55

66
// Set array format to repeat
77
$axios.onRequest(config => {
@@ -16,19 +16,14 @@ const axios: Plugin = ({$axios, redirect, $auth, route}) => {
1616
return response
1717
},
1818
async (error) => {
19-
console.log(route.path);
19+
if (error.response.status === 401 && app.router && app.router.currentRoute.path !== '/login') {
2020

21-
if (error.response.status === 401 && route.path !== '/login') {
2221
if($auth.loggedIn) {
23-
console.log('logged');
2422
await $auth.logout();
2523
}
2624

27-
console.log('redirect');
28-
2925
redirect(401, "/login");
3026
} else {
31-
console.log('return error');
3227
return Promise.reject(error);
3328
}
3429
});

0 commit comments

Comments
 (0)