Skip to content

Commit

Permalink
fix: exposing mfa in tppwless + cleanup/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Dec 10, 2023
1 parent fb74a61 commit ec913fb
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 103 deletions.
8 changes: 8 additions & 0 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@ function getThirdPartyPasswordlessConfigs({ staticProviderList, disableDefaultUI
disableDefaultUI,
style: theme.style,
},
mfaFeature: {
disableDefaultUI,
style: theme,
},
});
}

Expand Down Expand Up @@ -845,6 +849,10 @@ function getPasswordlessConfigs({ disableDefaultUI }) {
disableDefaultUI,
style: theme.style,
},
mfaFeature: {
disableDefaultUI,
style: theme,
},
});
}

Expand Down
6 changes: 5 additions & 1 deletion examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ function getThirdPartyPasswordlessConfigs({ staticProviderList, disableDefaultUI
disableDefaultUI,
style: theme,
},
mfaFeature: {
disableDefaultUI,
style: theme,
},
});
}

Expand Down Expand Up @@ -1078,7 +1082,7 @@ function getPasswordlessConfigs({ disableDefaultUI }) {
disableDefaultUI,
style: theme,
},
mfa: {
mfaFeature: {
disableDefaultUI,
style: theme,
},
Expand Down
82 changes: 27 additions & 55 deletions lib/build/passwordless-shared3.js

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

10 changes: 7 additions & 3 deletions lib/build/recipe/thirdpartypasswordless/prebuiltui.d.ts

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

1 change: 1 addition & 0 deletions lib/build/recipe/thirdpartypasswordless/types.d.ts

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

1 change: 1 addition & 0 deletions lib/build/thirdpartypasswordless-shared.js

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

16 changes: 15 additions & 1 deletion lib/build/thirdpartypasswordlessprebuiltui.js

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

61 changes: 22 additions & 39 deletions lib/ts/recipe/passwordless/components/features/mfa/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,48 +321,31 @@ function useOnLoad(
: mfaInfo.factors.isAllowedToSetup.includes("otp-phone");

if (!loginAttemptInfo) {
if (props.contactMethod === "EMAIL") {
if (isAlreadySetup && doSetup !== "true") {
try {
// createCode also dispatches the necessary events
await recipeImplementation!.createCode({
email: mfaInfo.email!, // We can assume this is set here, since the mfaInfo states that otp-email has been set up
userContext,
});
} catch (err) {
dispatch({ type: "setError", error: "SOMETHING_WENT_WRONG_ERROR" });
}
} else if (!mfaInfo.factors.isAllowedToSetup.includes("otp-email")) {
dispatch({
type: "load",
loginAttemptInfo,
isAllowedToSetup: false,
error: "PWLESS_MFA_OTP_NOT_ALLOWED_TO_SETUP",
// We can assume these are defined if we use these, we check that the mfaInfo states that the related factor has been set up
const createCodeInfo =
props.contactMethod === "EMAIL" ? { email: mfaInfo.email! } : { phoneNumber: mfaInfo.phoneNumber! };
const factorId = props.contactMethod === "EMAIL" ? "otp-email" : "otp-phone";

if (isAlreadySetup && doSetup !== "true") {
try {
// createCode also dispatches the necessary events
await recipeImplementation!.createCode({
...createCodeInfo,
userContext,
});
} else {
dispatch({ type: "load", loginAttemptInfo, error, isAllowedToSetup: true }); // since loginAttemptInfo is undefined, this will ask the user for the email
} catch (err) {
dispatch({ type: "setError", error: "SOMETHING_WENT_WRONG_ERROR" });
}
} else if (!mfaInfo.factors.isAllowedToSetup.includes(factorId)) {
dispatch({
type: "load",
loginAttemptInfo: undefined,
isAllowedToSetup: false,
error: "PWLESS_MFA_OTP_NOT_ALLOWED_TO_SETUP",
});
} else {
if (isAlreadySetup && doSetup !== "true") {
try {
// createCode also dispatches the necessary events
await recipeImplementation!.createCode({
phoneNumber: mfaInfo.phoneNumber!, // We can assume this is set here, since the mfaInfo states that otp-phone has been set up
userContext,
});
} catch (err) {
dispatch({ type: "setError", error: "SOMETHING_WENT_WRONG_ERROR" });
}
} else if (!mfaInfo.factors.isAllowedToSetup.includes("otp-phone")) {
dispatch({
type: "load",
loginAttemptInfo,
isAllowedToSetup: false,
error: "PWLESS_MFA_OTP_NOT_ALLOWED_TO_SETUP",
});
} else {
dispatch({ type: "load", loginAttemptInfo, error, isAllowedToSetup: true }); // since loginAttemptInfo is undefined, this will ask the user for the phone number
}
// since loginAttemptInfo is undefined, this will ask the user for the email/phone
dispatch({ type: "load", loginAttemptInfo, error, isAllowedToSetup: true });
}
} else {
// No need to check if the component is unmounting, since this has no effect then.
Expand Down
Loading

0 comments on commit ec913fb

Please sign in to comment.