Skip to content

Commit

Permalink
fix: small self-review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Dec 11, 2023
1 parent c1f3a48 commit e865afc
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 96 deletions.
2 changes: 1 addition & 1 deletion lib/build/emailverification-shared2.js

Large diffs are not rendered by default.

39 changes: 6 additions & 33 deletions lib/build/index2.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/build/multifactorauthprebuiltui.js

Large diffs are not rendered by default.

54 changes: 36 additions & 18 deletions lib/build/passwordless-shared4.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/build/passwordlessprebuiltui.js

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

4 changes: 3 additions & 1 deletion lib/build/recipe/passwordless/prebuiltui.d.ts

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/recipe/passwordless/types.d.ts

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/sessionprebuiltui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/build/thirdparty-shared2.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/build/thirdpartyemailpasswordprebuiltui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/build/thirdpartypasswordlessprebuiltui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/build/totpprebuiltui.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions lib/ts/recipe/emailpassword/components/themes/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@
margin: 0 auto;
}

[data-supertokens~="withBackButton"] {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
}

[data-supertokens~="resendEmailLink"] {
display: inline-block;
}
6 changes: 5 additions & 1 deletion lib/ts/recipe/passwordless/components/features/mfa/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export function useChildProps(
await recipeImplementation.clearLoginAttemptInfo({ userContext });
await redirectToAuth({ redirectBack: false, history: history });
},
onBackButtonClicked: () => {
onBackButtonClicked: async () => {
if (state.loginAttemptInfo) {
await recipeImplementation.clearLoginAttemptInfo({ userContext });
}
// If we don't have history available this would mean we are not using react-router-dom, so we use window's history
if (history === undefined) {
return WindowHandlerReference.getReferenceOrThrow().windowHandler.getWindowUnsafe().history.back();
Expand Down Expand Up @@ -342,6 +345,7 @@ function useOnLoad(
props.recipe.config.contactMethod,
dynamicLoginMethods
);

if (loginAttemptInfo && !enabledContactMethods.includes(loginAttemptInfo.contactMethod)) {
await recipeImplementation?.clearLoginAttemptInfo({ userContext });
loginAttemptInfo = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const MFAHeader = withOverride(
return (
<Fragment>
<div data-supertokens="headerTitle withBackButton pwless-mfa header">
{claim.loading === false && claim.value?.n.length === 0 ? (
{claim.loading === false && (claim.value === undefined || claim.value.n.length === 0) ? (
<BackButton onClick={props.onBackButtonClicked} />
) : (
<span data-supertokens="backButtonPlaceholder backButtonCommon">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const MFAOTPHeader = withOverride(
return (
<Fragment>
<div data-supertokens="headerTitle withBackButton pwless-mfa otpHeader">
{claim.loading === false && claim.value?.n.length === 0 && isSetupAllowed === false ? (
{claim.loading === false &&
(claim.value === undefined || claim.value.n.length === 0) &&
isSetupAllowed === false ? (
<BackButton onClick={onBackButtonClicked} />
) : (
<span data-supertokens="backButtonPlaceholder backButtonCommon">
Expand Down
4 changes: 3 additions & 1 deletion lib/ts/recipe/passwordless/prebuiltui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRecipeComponentOverrideContext } from "./componentOverrideContext";
import LinkClickedScreen from "./components/features/linkClickedScreen";
import MFAFeature from "./components/features/mfa";
import SignInUpFeature from "./components/features/signInAndUp";
import MFAOTPTheme from "./components/themes/mfa";
import SignInUpTheme from "./components/themes/signInUp";
import Passwordless from "./recipe";

Expand Down Expand Up @@ -199,6 +200,7 @@ export class PasswordlessPreBuiltUI extends RecipeRouter {
static LinkClicked = (prop?: any) => this.getFeatureComponent("linkClickedScreen", prop);
static MfaOtpPhone = (prop?: any) => this.getFeatureComponent("otp-phone", prop);
static MfaOtpEmail = (prop?: any) => this.getFeatureComponent("otp-email", prop);
static MFAOTPTheme = MFAOTPTheme;

static SignInUpTheme = SignInUpTheme;
}
Expand All @@ -208,4 +210,4 @@ const LinkClicked = PasswordlessPreBuiltUI.LinkClicked;
const MfaOtpPhone = PasswordlessPreBuiltUI.MfaOtpPhone;
const MfaOtpEmail = PasswordlessPreBuiltUI.MfaOtpEmail;

export { SignInUp, LinkClicked, SignInUpTheme, MfaOtpPhone, MfaOtpEmail };
export { SignInUp, LinkClicked, SignInUpTheme, MfaOtpPhone, MfaOtpEmail, MFAOTPTheme };
30 changes: 5 additions & 25 deletions lib/ts/recipe/recipeRouter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ const priorityOrder: {

function chooseComponentBasedOnFirstFactors(
firstFactors: string[],
routeComponents: ComponentWithRecipeAndMatchingMethod[],
allowSubRecipeComp: boolean
routeComponents: ComponentWithRecipeAndMatchingMethod[]
) {
let fallbackRid;
let fallbackComponent;
let subRecipeRid;
let subRecipeComponent;
// We first try to find an exact match, and fall back on something that covers all factors (but maybe more)
for (const { rid, factorsProvided } of priorityOrder) {
if (firstFactors.every((factor) => factorsProvided.includes(factor))) {
Expand All @@ -55,23 +52,10 @@ function chooseComponentBasedOnFirstFactors(
return matchingComp;
}
}
} else if (allowSubRecipeComp && factorsProvided.some((factor) => firstFactors.includes(factor))) {
const matchingComp = routeComponents.find((comp) => comp.recipeID === rid);
if (matchingComp) {
subRecipeRid = rid;
subRecipeComponent = matchingComp;
}
}
}

if (fallbackComponent === undefined) {
if (subRecipeComponent) {
logDebugMessage(
`Rendering ${subRecipeRid} because it overlaps factors: ${firstFactors} and we are not rendering the auth page`
);
return subRecipeComponent;
}

throw new Error("No enabled recipes overlap with the requested firstFactors: " + firstFactors);
}

Expand Down Expand Up @@ -133,12 +117,8 @@ export abstract class RecipeRouter {
return componentMatchingRid;
}

if (mfaRecipe && mfaRecipe.config.firstFactors !== undefined) {
return chooseComponentBasedOnFirstFactors(
mfaRecipe.config.firstFactors,
routeComponents,
isNonAuthPage
);
if (!isNonAuthPage && mfaRecipe && mfaRecipe.config.firstFactors !== undefined) {
return chooseComponentBasedOnFirstFactors(mfaRecipe.config.firstFactors, routeComponents);
} else {
return defaultComp;
}
Expand All @@ -159,8 +139,8 @@ export abstract class RecipeRouter {
return componentMatchingRid;
}

if (dynamicLoginMethods.firstFactors !== undefined) {
return chooseComponentBasedOnFirstFactors(dynamicLoginMethods.firstFactors, routeComponents, isNonAuthPage);
if (!isNonAuthPage && dynamicLoginMethods.firstFactors !== undefined) {
return chooseComponentBasedOnFirstFactors(dynamicLoginMethods.firstFactors, routeComponents);
}

// We may get here if the app is using an older BE that doesn't support MFA
Expand Down
7 changes: 7 additions & 0 deletions lib/ts/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,10 @@
margin-right: auto;
margin-top: 14px;
}

[data-supertokens~="withBackButton"] {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
}

0 comments on commit e865afc

Please sign in to comment.