Skip to content

Commit 230c027

Browse files
leedongweic298lee
authored andcommitted
fix(saml2): Fix redirect on logout (#77225)
Made a mistake on using `redirect` from `react-router-dom`. Going back to tried and tested.
1 parent 1f98048 commit 230c027

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {redirect} from 'react-router-dom';
2-
31
import {waitFor} from 'sentry-test/reactTestingLibrary';
42

53
import {logout} from './account';
@@ -8,15 +6,16 @@ jest.mock('react-router-dom');
86

97
describe('logout', () => {
108
it('has can logout', async function () {
11-
const mock = MockApiClient.addMockResponse({
9+
jest.spyOn(window.location, 'assign').mockImplementation(() => {});
10+
const mockApi = new MockApiClient();
11+
const mockApiDelete = MockApiClient.addMockResponse({
1212
url: '/auth/',
1313
method: 'DELETE',
1414
});
1515

16-
const api = new MockApiClient();
17-
logout(api);
16+
logout(mockApi);
1817

19-
await waitFor(() => expect(mock).toHaveBeenCalled());
20-
await waitFor(() => expect(redirect).toHaveBeenCalled());
18+
await waitFor(() => expect(mockApiDelete).toHaveBeenCalled());
19+
expect(window.location.assign).toHaveBeenCalledWith('/auth/login/');
2120
});
2221
});

static/app/actionCreators/account.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {redirect} from 'react-router-dom';
2-
31
import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
42
import {Client} from 'sentry/api';
53
import ConfigStore from 'sentry/stores/configStore';
@@ -52,7 +50,7 @@ export async function logout(api: Client, redirectUrl = '/auth/login/') {
5250
const data = await api.requestPromise('/auth/', {method: 'DELETE'});
5351

5452
// If there's a URL for SAML Single-logout, redirect back to IdP
55-
redirect(data?.sloUrl || redirectUrl);
53+
window.location.assign(data?.sloUrl || redirectUrl);
5654
}
5755

5856
export function removeAuthenticator(api: Client, userId: string, authId: string) {

0 commit comments

Comments
 (0)