Skip to content

Commit ff58b59

Browse files
[refactor]: handling the token expiry case
- Github Issue: Authored-by: Shubham Bansal <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
1 parent 702d81b commit ff58b59

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: nuxt.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
/*
3838
** Plugins to load before mounting the App
3939
*/
40-
plugins: ['@/plugins/vuetify'],
40+
plugins: ['@/plugins/vuetify', '@/plugins/axios'],
4141

4242
/*
4343
** Nuxt.js modules

Diff for: plugins/axios.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* redirect the admin panel to the homepage in-case of token expiry
3+
* @param {[type]} options.$axios [description]
4+
* @param {[type]} options.redirect [description]
5+
* @return {[type]} [description]
6+
*/
7+
export default function({ $axios, redirect }) {
8+
$axios.onError(error => {
9+
const code = parseInt(error.response && error.response.status)
10+
if (code === 500 && error.response.data.message === 'Token has expired') {
11+
redirect('/')
12+
}
13+
})
14+
}

0 commit comments

Comments
 (0)