Client - handle path type on interceptors
This commit is contained in:
parent
5a4dd60e41
commit
2e1ee2c7a1
@ -1,15 +1,24 @@
|
|||||||
|
const updatePath = (toPath, newPath) => {
|
||||||
|
if (typeof toPath === 'string' || toPath instanceof String) {
|
||||||
|
toPath = newPath
|
||||||
|
} else {
|
||||||
|
toPath.pathname = newPath
|
||||||
|
}
|
||||||
|
return toPath
|
||||||
|
}
|
||||||
|
|
||||||
const pathInterceptor = toPath => {
|
const pathInterceptor = toPath => {
|
||||||
if (
|
if (
|
||||||
!window.localStorage.authToken &&
|
!window.localStorage.authToken &&
|
||||||
!['/login', '/register'].includes(toPath.pathname)
|
!['/login', '/register'].includes(toPath.pathname)
|
||||||
) {
|
) {
|
||||||
toPath.pathname = '/login'
|
toPath = updatePath(toPath, '/login')
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
window.localStorage.authToken &&
|
window.localStorage.authToken &&
|
||||||
['/login', '/register'].includes(toPath.pathname)
|
['/login', '/register'].includes(toPath.pathname)
|
||||||
) {
|
) {
|
||||||
toPath.pathname = '/'
|
toPath = updatePath(toPath, '/')
|
||||||
}
|
}
|
||||||
return toPath
|
return toPath
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user