Skip to content

Commit

Permalink
fix: use window location for redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
waynelwz committed Sep 5, 2022
1 parent d95f538 commit ede6aa2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions console/src/api/ApiHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,31 @@ export default function ApiHeader() {
(error) => {
// eslint-disable-next-line no-restricted-globals
// eslint-disable-next-line prefer-destructuring
const winLocation = window.location

if (error.response?.status === 401) {
setToken(undefined)
}

if (error.response?.status === 401 && error.config.method === 'get') {
const withUnAuthRoute =
['/login', '/signup', '/create-account', 'logout'].filter((path) =>
location.pathname.includes(path)
winLocation.pathname.includes(path)
).length > 0
const search = qs.parse(location.search, { ignoreQueryPrefix: true })
const search = qs.parse(winLocation.search, { ignoreQueryPrefix: true })
let { redirect } = search
if (redirect && typeof redirect === 'string') {
redirect = decodeURI(redirect)
} else if (!withUnAuthRoute) {
redirect = `${location.pathname}${location.search}`
redirect = `${winLocation.pathname}${winLocation.search}`
} else {
redirect = '/projects'
}

if (!withUnAuthRoute) {
location.href = `${location.protocol}//${location.host}/login?redirect=${encodeURIComponent(
redirect
)}`
winLocation.href = `${winLocation.protocol}//${
winLocation.host
}/login?redirect=${encodeURIComponent(redirect)}`
}
}

Expand Down

0 comments on commit ede6aa2

Please sign in to comment.