Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Mar 27, 2024
1 parent 10e3b61 commit 67c85cc
Show file tree
Hide file tree
Showing 9 changed files with 19,646 additions and 743 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.39.1] - 2024-03-27

- Fixes how we fetch the component to render based on the current path to take into account non auth recipes correctly.
- Adds Remix example reference.

## [0.39.0] - 2024-03-07
Expand Down
2 changes: 1 addition & 1 deletion lib/build/genericComponentOverrideContext.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 40 additions & 20 deletions lib/build/index2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 30 additions & 16 deletions lib/ts/recipe/recipeRouter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,43 @@ export abstract class RecipeRouter {
routePath === path ||
new RegExp("^" + routePath.replace(/:\w+/g, "[^/]+").replace(/\/\*/g, "/[^/]+") + "$").test(path)
) {
components = components.concat(routeComps);
components = components.concat(
routeComps.map((c) => {
return { comp: c, route: routePath };
})
);
}
}
return components;
}, [] as ComponentWithRecipeAndMatchingMethod[]);
}, [] as { comp: ComponentWithRecipeAndMatchingMethod; route: string }[]);

// We check the query params to see if any recipe was requested by id
const componentMatchingRid = routeComponents.find((c) => c.matches());
const componentMatchingRid = routeComponents.find((c) => c.comp.matches());

// We default to to one requested by id or the first in the list
// i.e.: the first prebuilt ui in the list the user provided that can handle this route.
let defaultComp;
let defaultComp: ComponentWithRecipeAndMatchingMethod | undefined;
if (routeComponents.length === 0) {
defaultComp = undefined;
} else if (componentMatchingRid !== undefined) {
defaultComp = componentMatchingRid;
defaultComp = componentMatchingRid.comp;
} else {
defaultComp = routeComponents[0];
defaultComp = routeComponents[0].comp;
}

// We check if any non-auth recipe (emailverification, totp) can handle this
// There should be no overlap between the routes handled by those and the auth recipes
// so if there is a match we can return early
const matchingNonAuthComponent = routeComponents.find(
(comp) => !priorityOrder.map((a) => a.rid).includes(comp.recipeID)
);
const matchingNonAuthComponent = routeComponents.find((comp) => {
const ridlist = priorityOrder.map((a) => a.rid);
return (
!ridlist.includes(comp.comp.recipeID) ||
comp.route !== SuperTokens.getInstanceOrThrow().appInfo.websiteBasePath.getAsStringDangerous()
);
});

if (matchingNonAuthComponent) {
return matchingNonAuthComponent;
return matchingNonAuthComponent.comp;
}

// We use this option in `canHandleRoute`, because it may be called by custom UIs before
Expand All @@ -205,14 +213,17 @@ export abstract class RecipeRouter {
if (SuperTokens.usesDynamicLoginMethods === false) {
// If we are not using dynamic login methods, we can use the rid requested by the app
if (componentMatchingRid) {
return componentMatchingRid;
return componentMatchingRid.comp;
}

// if we have a static firstFactors config we take it into account on the auth page
// Other pages shouldn't care about this configuration.
// Embedded components are not affected, since this is only called by the routing component.
if (isAuthPage && mfaRecipe && mfaRecipe.config.firstFactors !== undefined) {
return chooseComponentBasedOnFirstFactors(mfaRecipe.config.firstFactors, routeComponents);
return chooseComponentBasedOnFirstFactors(
mfaRecipe.config.firstFactors,
routeComponents.map((c) => c.comp)
);
} else {
return defaultComp;
}
Expand All @@ -227,21 +238,24 @@ export abstract class RecipeRouter {
// If we are using dynamic login methods, we check that the requested rid belongs to an enabled recipe
if (
componentMatchingRid && // if we find a component matching by rid
(!priorityOrder.map((a) => a.rid).includes(componentMatchingRid.recipeID) || // from a non-auth recipe
(!priorityOrder.map((a) => a.rid).includes(componentMatchingRid.comp.recipeID) || // from a non-auth recipe
priorityOrder.some(
(a) =>
a.rid === componentMatchingRid.recipeID &&
a.rid === componentMatchingRid.comp.recipeID &&
a.factorsProvided.some((factorId) => dynamicLoginMethods.firstFactors.includes(factorId))
)) // or an enabled auth recipe
) {
return componentMatchingRid;
return componentMatchingRid.comp;
}

// if we have a firstFactors config for the tenant we take it into account on the auth page
// Other pages shouldn't care about this configuration.
// Embedded components are not affected, since this is only called by the routing component.
if (isAuthPage) {
return chooseComponentBasedOnFirstFactors(dynamicLoginMethods.firstFactors, routeComponents);
return chooseComponentBasedOnFirstFactors(
dynamicLoginMethods.firstFactors,
routeComponents.map((c) => c.comp)
);
}

return undefined;
Expand Down
1 change: 0 additions & 1 deletion lib/ts/recipe/thirdpartypasswordless/prebuiltui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export class ThirdPartyPasswordlessPreBuiltUI extends RecipeRouter {
recipeID: ThirdPartyPasswordless.RECIPE_ID,
};
}

return {
...features,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const package_version = "0.39.0";
export const package_version = "0.39.1";
Loading

0 comments on commit 67c85cc

Please sign in to comment.