diff --git a/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts b/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts index 39d5022be8a0b..fa75148afe624 100644 --- a/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts +++ b/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts @@ -232,6 +232,8 @@ export default class SupersetClientClass { } redirectUnauthorized() { - window.location.href = `/login?next=${window.location.href}`; + window.location.href = `/login?next=${ + window.location.pathname + window.location.search + }`; } } diff --git a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts index 4efd4f43ca685..ae6ac138d5a67 100644 --- a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts @@ -501,11 +501,16 @@ describe('SupersetClientClass', () => { it('should redirect Unauthorized', async () => { const mockRequestUrl = 'https://host/get/url'; + const mockRequestPath = '/get/url'; + const mockRequestSearch = '?param=1¶m=2'; const { location } = window; // @ts-ignore delete window.location; // @ts-ignore - window.location = { href: mockRequestUrl }; + window.location = { + pathname: mockRequestPath, + search: mockRequestSearch, + }; const authSpy = jest .spyOn(SupersetClientClass.prototype, 'ensureAuth') .mockImplementation(); @@ -523,7 +528,9 @@ describe('SupersetClientClass', () => { error = err; } finally { const redirectURL = window.location.href; - expect(redirectURL).toBe(`/login?next=${mockRequestUrl}`); + expect(redirectURL).toBe( + `/login?next=${mockRequestPath + mockRequestSearch}`, + ); expect(error.status).toBe(401); }