♻️(frontend) redirect the user agent to the logout endpoint

Recent updates in the backend views now requires the user agent to be
redirected to the logout endpoint.

The logout endpoint should initiate the logout flow with the OIDC provider,
by redirecting the user to the OIDC provider domain.

Thus, OIDC provider session cookie should be cleared.

E2E tests should be improved later on, when the CI and the development env
use Agent Connect integration environment. The current logout is not working
with the Keycloack configuration.
This commit is contained in:
Lebaud Antoine
2024-05-31 12:14:58 +02:00
committed by aleb_the_flash
parent 7a26f377e3
commit 63a875bd5b
5 changed files with 9 additions and 28 deletions
@@ -34,22 +34,14 @@ describe('fetchAPI', () => {
});
it('logout if 401 response', async () => {
useAuthStore.setState({
authenticated: true,
userData: { id: '123', email: '[email protected]' },
});
const logoutMock = jest.fn();
jest
.spyOn(useAuthStore.getState(), 'logout')
.mockImplementation(logoutMock);
fetchMock.mock('http://some.api.url/api/v1.0/some/url', 401);
fetchMock.mock('http://some.api.url/api/v1.0/logout/', 302);
await fetchAPI('some/url');
await Promise.all([fetchMock.flush()]);
expect(fetchMock.lastUrl()).toEqual('http://some.api.url/api/v1.0/logout/');
const { userData, authenticated } = useAuthStore.getState();
expect(userData).toBeUndefined();
expect(authenticated).toBeFalsy();
expect(logoutMock).toHaveBeenCalled();
});
});
@@ -1,3 +1,2 @@
export * from './types';
export * from './getMe';
export * from './logout';
@@ -1,8 +0,0 @@
import { fetchAPI } from '@/api';
export const logout = async () => {
await fetchAPI(`logout/`, {
method: 'POST',
redirect: 'manual',
});
};
@@ -1,6 +1,6 @@
import { create } from 'zustand';
import { User, getMe, logout } from './api';
import { User, getMe } from './api';
export const login = () => {
window.location.replace(
@@ -34,8 +34,8 @@ export const useAuthStore = create<AuthStore>((set) => ({
});
},
logout: () => {
void logout().then(() => {
set(initialState);
});
window.location.replace(
new URL('logout/', process.env.NEXT_PUBLIC_API_URL).href,
);
},
}));
@@ -50,8 +50,6 @@ test.describe('Header', () => {
})
.click();
// FIXME - assert the session has been killed in Keycloak
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
});