Browse Source

fix(saml2): Fix redirect on logout (#77225)

Made a mistake on using `redirect` from `react-router-dom`.

Going back to tried and tested.
Danny Lee 6 months ago
parent
commit
cbebd2dd12

+ 6 - 7
static/app/actionCreators/account.spec.tsx

@@ -1,5 +1,3 @@
-import {redirect} from 'react-router-dom';
-
 import {waitFor} from 'sentry-test/reactTestingLibrary';
 
 import {logout} from './account';
@@ -8,15 +6,16 @@ jest.mock('react-router-dom');
 
 describe('logout', () => {
   it('has can logout', async function () {
-    const mock = MockApiClient.addMockResponse({
+    jest.spyOn(window.location, 'assign').mockImplementation(() => {});
+    const mockApi = new MockApiClient();
+    const mockApiDelete = MockApiClient.addMockResponse({
       url: '/auth/',
       method: 'DELETE',
     });
 
-    const api = new MockApiClient();
-    logout(api);
+    logout(mockApi);
 
-    await waitFor(() => expect(mock).toHaveBeenCalled());
-    await waitFor(() => expect(redirect).toHaveBeenCalled());
+    await waitFor(() => expect(mockApiDelete).toHaveBeenCalled());
+    expect(window.location.assign).toHaveBeenCalledWith('/auth/login/');
   });
 });

+ 1 - 3
static/app/actionCreators/account.tsx

@@ -1,5 +1,3 @@
-import {redirect} from 'react-router-dom';
-
 import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
 import {Client} from 'sentry/api';
 import ConfigStore from 'sentry/stores/configStore';
@@ -52,7 +50,7 @@ export async function logout(api: Client, redirectUrl = '/auth/login/') {
   const data = await api.requestPromise('/auth/', {method: 'DELETE'});
 
   // If there's a URL for SAML Single-logout, redirect back to IdP
-  redirect(data?.sloUrl || redirectUrl);
+  window.location.assign(data?.sloUrl || redirectUrl);
 }
 
 export function removeAuthenticator(api: Client, userId: string, authId: string) {