optimized user auth

This commit is contained in:
Marvin Zhang
2019-07-27 14:55:03 +08:00
parent eea85faa5c
commit 66a33e83ac
8 changed files with 121 additions and 45 deletions

View File

@@ -1,4 +1,5 @@
import axios from 'axios'
import router from '../router'
let baseUrl = process.env.VUE_APP_BASE_URL ? process.env.VUE_APP_BASE_URL : 'http://localhost:8000/api'
@@ -16,7 +17,13 @@ const request = (method, path, params, data) => {
headers
})
.then(resolve)
.catch(reject)
.catch(error => {
console.log(error)
if (error.response.status === 401) {
router.push('/login')
}
reject(error)
})
})
}