Skip to content

Commit

Permalink
Client - handle path type on interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
SamR1 committed Jan 31, 2020
1 parent 5a4dd60 commit 2e1ee2c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fittrackee_client/src/utils/history.js
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down

0 comments on commit 2e1ee2c

Please sign in to comment.