From 2e1ee2c7a1456eb2fe0c0255959c695cc7908975 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 31 Jan 2020 15:06:11 +0100 Subject: [PATCH] Client - handle path type on interceptors --- fittrackee_client/src/utils/history.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fittrackee_client/src/utils/history.js b/fittrackee_client/src/utils/history.js index 3da7b17f..5d2209af 100644 --- a/fittrackee_client/src/utils/history.js +++ b/fittrackee_client/src/utils/history.js @@ -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 }