File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed
Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import qs from 'qs'
2+ import { Plugin } from '@nuxt/types'
3+
4+ const axios : Plugin = ( { $axios, redirect, $auth} ) => {
5+
6+ // Set array format to repeat
7+ $axios . onRequest ( config => {
8+ config . paramsSerializer = ( params ) => {
9+ return qs . stringify ( params , { arrayFormat : 'repeat' } )
10+ }
11+ } ) ;
12+
13+ // Disconnect user (if connected) when 401 error and redirect to login page
14+ $axios . interceptors . response . use (
15+ function ( response ) {
16+ return response
17+ } ,
18+ async ( error ) => {
19+ if ( error . response . status === 401 ) {
20+ if ( $auth . loggedIn ) {
21+ await $auth . logout ( ) ;
22+ }
23+ redirect ( 401 , "/login" ) ;
24+ } else {
25+ return Promise . reject ( error ) ;
26+ }
27+ } ) ;
28+
29+ } ;
30+
31+ export default axios
You can’t perform that action at this time.
0 commit comments