@axa-fr/react-oidc 7.27.12 → 7.27.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,11 +13,22 @@ export const CallBackSuccess: ComponentType<any> = () => (
13
13
  </div>
14
14
  );
15
15
 
16
+ const NAVIGATION_VERIFICATION_DELAY_MS = 200;
17
+
18
+ export const verifyNavigationCommitted = (
19
+ targetPath: string,
20
+ windowInternal: Window = window,
21
+ ): boolean => {
22
+ const currentPath = windowInternal.location.pathname;
23
+ return currentPath === targetPath || targetPath === '/';
24
+ };
25
+
16
26
  const CallbackManager: ComponentType<any> = ({
17
27
  callBackError,
18
28
  callBackSuccess,
19
29
  configurationName,
20
30
  withCustomHistory,
31
+ navigateAfterCallback,
21
32
  }) => {
22
33
  const [isError, setIsError] = useState(false);
23
34
  useEffect(() => {
@@ -25,9 +36,57 @@ const CallbackManager: ComponentType<any> = ({
25
36
  const playCallbackAsync = async () => {
26
37
  const getOidc = OidcClient.get;
27
38
  try {
28
- const { callbackPath } = await getOidc(configurationName).loginCallbackAsync();
29
- const history = withCustomHistory ? withCustomHistory() : getCustomHistory();
30
- history.replaceState(callbackPath || '/');
39
+ const oidcClient = getOidc(configurationName);
40
+ const { callbackPath } = await oidcClient.loginCallbackAsync();
41
+ const targetPath = callbackPath || '/';
42
+
43
+ if (navigateAfterCallback) {
44
+ try {
45
+ await navigateAfterCallback(targetPath);
46
+ oidcClient.publishEvent(OidcClient.eventNames.loginCallbackAsync_navigated, {
47
+ configurationName,
48
+ callbackPath: targetPath,
49
+ });
50
+ } catch (navigationError) {
51
+ oidcClient.publishEvent(OidcClient.eventNames.loginCallbackAsync_navigation_error, {
52
+ configurationName,
53
+ callbackPath: targetPath,
54
+ error: navigationError,
55
+ });
56
+ if (isMounted) {
57
+ console.warn(navigationError);
58
+ setIsError(true);
59
+ }
60
+ }
61
+ } else {
62
+ const history = withCustomHistory ? withCustomHistory() : getCustomHistory();
63
+ history.replaceState(targetPath);
64
+
65
+ await new Promise<void>(resolve => {
66
+ setTimeout(() => {
67
+ resolve();
68
+ }, NAVIGATION_VERIFICATION_DELAY_MS);
69
+ });
70
+
71
+ if (isMounted) {
72
+ const committed = verifyNavigationCommitted(targetPath);
73
+ if (committed) {
74
+ oidcClient.publishEvent(OidcClient.eventNames.loginCallbackAsync_navigated, {
75
+ configurationName,
76
+ callbackPath: targetPath,
77
+ });
78
+ } else {
79
+ oidcClient.publishEvent(OidcClient.eventNames.loginCallbackAsync_navigation_error, {
80
+ configurationName,
81
+ callbackPath: targetPath,
82
+ error: new Error(
83
+ `Navigation did not commit: expected "${targetPath}" but found "${window.location.pathname}"`,
84
+ ),
85
+ });
86
+ setIsError(true);
87
+ }
88
+ }
89
+ }
31
90
  } catch (error) {
32
91
  if (isMounted) {
33
92
  console.warn(error);
@@ -0,0 +1,14 @@
1
+ import { ComponentType } from 'react';
2
+
3
+ const LoadingTimeout: ComponentType<any> = () => (
4
+ <div className="oidc-loading-timeout">
5
+ <div className="oidc-loading-timeout__container">
6
+ <h1 className="oidc-loading-timeout__title">Loading timeout</h1>
7
+ <p className="oidc-loading-timeout__content">
8
+ Authentication is taking longer than expected. Please try refreshing the page.
9
+ </p>
10
+ </div>
11
+ </div>
12
+ );
13
+
14
+ export default LoadingTimeout;
@@ -2,5 +2,6 @@ export { default as AuthenticateError } from './AuthenticateError.component.js';
2
2
  export { default as Authenticating } from './Authenticating.component.js';
3
3
  export { default as Callback, CallBackSuccess } from './Callback.component.js';
4
4
  export { default as Loading } from './Loading.component.js';
5
+ export { default as LoadingTimeout } from './LoadingTimeout.component.js';
5
6
  export { default as ServiceWorkerNotSupported } from './ServiceWorkerNotSupported.component.js';
6
7
  export { default as SessionLost } from './SessionLost.component.js';
@@ -15,6 +15,7 @@ type OidcRoutesProps = {
15
15
  silent_redirect_uri?: string;
16
16
  silent_login_uri?: string;
17
17
  withCustomHistory?: () => CustomHistory;
18
+ navigateAfterCallback?: (callbackPath: string) => Promise<void>;
18
19
  location: ILOidcLocation;
19
20
  };
20
21
 
@@ -27,6 +28,7 @@ const OidcRoutes: FC<PropsWithChildren<OidcRoutesProps>> = ({
27
28
  children,
28
29
  configurationName,
29
30
  withCustomHistory = null,
31
+ navigateAfterCallback = null,
30
32
  }) => {
31
33
  // This exist because in next.js window outside useEffect is null
32
34
  const pathname = window ? getPath(window.location.href) : '';
@@ -62,6 +64,7 @@ const OidcRoutes: FC<PropsWithChildren<OidcRoutesProps>> = ({
62
64
  callBackSuccess={callbackSuccessComponent}
63
65
  configurationName={configurationName}
64
66
  withCustomHistory={withCustomHistory}
67
+ navigateAfterCallback={navigateAfterCallback}
65
68
  />
66
69
  );
67
70
  default:
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { useOidcFetch, withOidcFetch } from './FetchToken.js';
2
+ export type { OidcProviderProps } from './OidcProvider.js';
2
3
  export { OidcProvider } from './OidcProvider.js';
3
4
  export { OidcSecure, withOidcSecure } from './OidcSecure.js';
4
5
  export { useOidc, useOidcAccessToken, useOidcIdToken } from './ReactOidc.js';