Skip to content

Commit f7c0e07

Browse files
committed
ARTESCA-14759: We store the redirectUrl in the localstorage and this has become very flaky in the UI e2e test
Now we don't need to store it in the localstorage anymore, we can keep it in the state.
1 parent 906a0e7 commit f7c0e07

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

shell-ui/src/FederatedApp.tsx

+20-27
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@ import {
88
FederatedComponentProps,
99
SolutionUI,
1010
} from '@scality/module-federation';
11-
import React, {
12-
useEffect,
13-
useLayoutEffect,
14-
useMemo,
15-
useTransition,
16-
useRef,
17-
useState,
18-
} from 'react';
11+
import React, { useEffect, useMemo } from 'react';
1912
import { ErrorBoundary } from 'react-error-boundary';
2013
import { QueryClient } from 'react-query';
21-
import { BrowserRouter, Route, Routes, useLocation } from 'react-router';
14+
import { BrowserRouter, Route, Routes } from 'react-router';
2215

2316
import { loadShare } from '@module-federation/enhanced/runtime';
2417
import { useQuery } from 'react-query';
@@ -242,23 +235,21 @@ function InternalApp() {
242235
});
243236

244237
return (
245-
<BrowserRouter>
246-
<ShellHistoryProvider>
247-
<FirstTimeLoginProvider>
248-
<NotificationCenterProvider>
249-
{(status === 'idle' || status === 'loading') && (
250-
<Loader size="massive" centered={true} aria-label="loading" />
251-
)}
252-
{status === 'error' && <ErrorPage500 data-cy="sc-error-page500" />}
253-
{status === 'success' && (
254-
<SolutionsNavbar>
255-
<InternalRouter />
256-
</SolutionsNavbar>
257-
)}
258-
</NotificationCenterProvider>
259-
</FirstTimeLoginProvider>
260-
</ShellHistoryProvider>
261-
</BrowserRouter>
238+
<ShellHistoryProvider>
239+
<FirstTimeLoginProvider>
240+
<NotificationCenterProvider>
241+
{(status === 'idle' || status === 'loading') && (
242+
<Loader size="massive" centered={true} aria-label="loading" />
243+
)}
244+
{status === 'error' && <ErrorPage500 data-cy="sc-error-page500" />}
245+
{status === 'success' && (
246+
<SolutionsNavbar>
247+
<InternalRouter />
248+
</SolutionsNavbar>
249+
)}
250+
</NotificationCenterProvider>
251+
</FirstTimeLoginProvider>
252+
</ShellHistoryProvider>
262253
);
263254
}
264255

@@ -272,7 +263,9 @@ export function WithInitFederationProviders({
272263
<UIListProvider discoveryURL={shellConfig.discoveryUrl}>
273264
<ConfigurationProvider>
274265
<AuthConfigProvider>
275-
<AuthProvider>{children}</AuthProvider>
266+
<BrowserRouter>
267+
<AuthProvider>{children}</AuthProvider>
268+
</BrowserRouter>
276269
</AuthConfigProvider>
277270
</ConfigurationProvider>
278271
</UIListProvider>

shell-ui/src/auth/AuthProvider.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
import { useShellConfig } from '../initFederation/ShellConfigProvider';
1616
import { getUserGroups } from '../navbar/auth/permissionUtils';
1717
import { useAuthConfig } from './AuthConfigProvider';
18+
import { useNavigate } from 'react-router-dom';
1819
export function AuthProvider({ children }: { children: React.ReactNode }) {
1920
const { authConfig } = useAuthConfig();
2021

@@ -101,6 +102,7 @@ function OAuth2AuthProvider({ children }: { children: React.ReactNode }) {
101102
});
102103
};
103104
const { logOut } = useInternalLogout(userManager, authConfig);
105+
const navigate = useNavigate();
104106
//Force logout on silent renewal error
105107
useEffect(() => {
106108
const onSilentRenewError = (err) => {
@@ -125,15 +127,12 @@ function OAuth2AuthProvider({ children }: { children: React.ReactNode }) {
125127
}, [logOut]);
126128
const oidcConfig: AuthProviderProps = {
127129
onBeforeSignIn: () => {
128-
localStorage.setItem('redirectUrl', window.location.href);
129-
return window.location.href;
130+
return location.pathname + location.search + location.hash;
130131
},
131-
onSignIn: () => {
132-
const savedRedirectUri = localStorage.getItem('redirectUrl');
133-
localStorage.removeItem('redirectUrl');
134-
132+
onSignIn: (userData) => {
133+
const savedRedirectUri = userData.state;
135134
if (savedRedirectUri) {
136-
location.href = savedRedirectUri;
135+
navigate(savedRedirectUri);
137136
} else {
138137
const searchParams = new URLSearchParams(location.search);
139138
searchParams.delete('state');

0 commit comments

Comments
 (0)