Client - handle path type on interceptors

This commit is contained in:
Sam 2020-01-31 15:06:11 +01:00
parent 5a4dd60e41
commit 2e1ee2c7a1

View File

@ -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 => {
if (
!window.localStorage.authToken &&
!['/login', '/register'].includes(toPath.pathname)
) {
toPath.pathname = '/login'
toPath = updatePath(toPath, '/login')
}
if (
window.localStorage.authToken &&
['/login', '/register'].includes(toPath.pathname)
) {
toPath.pathname = '/'
toPath = updatePath(toPath, '/')
}
return toPath
}