mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-08-12 00:22:23 +00:00
Added router push if received 401 on client side
This commit is contained in:
parent
5c58f548c0
commit
9424ad1f13
@ -1,16 +1,23 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
export const requestURl = (url) => {
|
export const requestURl = (url) => {
|
||||||
return import.meta.env.MODE === 'development' ? '/client' + url
|
return import.meta.env.MODE === 'development' ? '/client' + url
|
||||||
: `${window.location.protocol}//${(window.location.host + window.location.pathname + url).replace(/\/\//g, '/')}`
|
: `${window.location.protocol}//${(window.location.host + window.location.pathname + url).replace(/\/\//g, '/')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
export const axiosPost = async (URL, body = {}) => {
|
export const axiosPost = async (URL, body = {}) => {
|
||||||
try{
|
try{
|
||||||
const res = await axios.post(requestURl(URL), body)
|
const res = await axios.post(requestURl(URL), body)
|
||||||
return res.data
|
return res.data
|
||||||
} catch (error){
|
} catch (error){
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
if (error.status === 401){
|
||||||
|
await router.push('/signin')
|
||||||
|
}
|
||||||
|
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,6 +28,9 @@ export const axiosGet = async (URL, query = {}) => {
|
|||||||
return res.data
|
return res.data
|
||||||
} catch (error){
|
} catch (error){
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
if (error.status === 401){
|
||||||
|
await router.push('/signin')
|
||||||
|
}
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user