From e849199eb0a9ecba4f9845aa1e07df775d5ded9b Mon Sep 17 00:00:00 2001 From: James Petts Date: Fri, 11 Oct 2024 14:09:26 +0100 Subject: [PATCH] fix(auth): oidc-react-issue (#4410) Co-authored-by: James Petts --- platform/app/src/routes/Mode/Mode.tsx | 5 ++++- platform/app/src/utils/OpenIdConnectRoutes.tsx | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/platform/app/src/routes/Mode/Mode.tsx b/platform/app/src/routes/Mode/Mode.tsx index 95338e64362..6d945eaaf7c 100644 --- a/platform/app/src/routes/Mode/Mode.tsx +++ b/platform/app/src/routes/Mode/Mode.tsx @@ -95,7 +95,10 @@ export default function ModeRoute({ await extensionManager.registerExtension(extension); } } - setExtensionDependenciesLoaded(true); + + if (isMounted.current) { + setExtensionDependenciesLoaded(true); + } }; loadExtensions(); diff --git a/platform/app/src/utils/OpenIdConnectRoutes.tsx b/platform/app/src/utils/OpenIdConnectRoutes.tsx index de044161a8e..4be2b9abd1c 100644 --- a/platform/app/src/utils/OpenIdConnectRoutes.tsx +++ b/platform/app/src/utils/OpenIdConnectRoutes.tsx @@ -44,7 +44,7 @@ const initUserManager = (oidc, routerBasename) => { post_logout_redirect_uri: _makeAbsoluteIfNecessary(post_logout_redirect_uri, baseUri), }); - const client = firstOpenIdClient.useAuthorizationCodeFlow ? NextClient: LegacyClient + const client = firstOpenIdClient.useAuthorizationCodeFlow ? NextClient : LegacyClient return client(openIdConnectConfiguration); }; @@ -110,8 +110,10 @@ function OpenIdConnectRoutes({ oidc, routerBasename, userAuthenticationService } }; }; - const handleUnauthenticated = async () => { - await userManager.signinRedirect(); + const handleUnauthenticated = () => { + // Note: Don't await the redirect. If you make this component async it + // causes a react error before redirect as it returns a promise of a component rather than a component. + userManager.signinRedirect(); // return null because this is used in a react component return null;