From 6e47f2ec061e0c3bfcd8e7f8cc44d4f1dea9a608 Mon Sep 17 00:00:00 2001 From: Alexander Dusenbery Date: Wed, 25 Sep 2024 15:26:29 -0400 Subject: [PATCH] feat: create a route to handle invite keys that includes the customer slug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing universal link route does not contain the enterprise slug, so for unauthenticated users, the frontend has no knowledge of which customer’s branded logistration for which to redirect. This is typically relied upon based on the `:enterpriseSlug` route parameter in the URL, which is missing for the existing universal link route. This change adds a new invite key route that includes the enterprise slug (but not under the root loader). This will enable us to produce slug-aware invite URLs from the admin portal, that receiving learners can use to become linked to the enterprise via the B2B-specific auth flow (which is customer-aware). ENT-9428 --- .../app/routes/createAppRouter.test.jsx | 8 +++++++ src/routes.tsx | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/components/app/routes/createAppRouter.test.jsx b/src/components/app/routes/createAppRouter.test.jsx index baee53fbaf..80f810af44 100644 --- a/src/components/app/routes/createAppRouter.test.jsx +++ b/src/components/app/routes/createAppRouter.test.jsx @@ -134,6 +134,14 @@ describe('createAppRouter', () => { usesQueryClient: false, }], }, + { + currentRoutePath: '/test-enterprise/invite/enterprise-customer-invite-key', + expectedRouteTestId: 'invite', + expectedRouteLoaders: [{ + loader: makeEnterpriseInviteLoader, + usesQueryClient: false, + }], + }, { currentRoutePath: '/test-enterprise', expectedRouteTestId: 'dashboard', diff --git a/src/routes.tsx b/src/routes.tsx index ae89823b99..f9314201f9 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -214,6 +214,28 @@ function getOtherRoutes() { }; }, }, + { + /** + * We want to support a slug-"aware" version of the invite key route, + * but we don't want it nested under the root loader via + * enterpriseSlugRoutes above. Putting this route under the root loader + * would mean that the post-registration redirect back to this route + * would run through the root loader logic with a now-authenticated-but-unlinked + * requesting user, which will throw a 404 (until the async call to + * `link-user/` resolves and the page is reloaded). + */ + path: ':enterpriseSlug/invite/:enterpriseCustomerInviteKey', + lazy: async () => { + const { + default: EnterpriseInviteRoute, + makeEnterpriseInviteLoader, + } = await import('./components/app/routes/EnterpriseInviteRoute'); + return { + Component: EnterpriseInviteRoute, + loader: makeEnterpriseInviteLoader(), + }; + }, + }, ]; return otherRoutes; }