Skip to content

Commit

Permalink
feat: factor chooser fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Oct 19, 2023
1 parent 8932a0e commit ad99b5f
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 87 deletions.
2 changes: 1 addition & 1 deletion lib/build/index2.js

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

57 changes: 44 additions & 13 deletions lib/build/multifactorauth-shared.js

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

64 changes: 34 additions & 30 deletions lib/build/multifactorauthprebuiltui.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/recipe/multifactorauth/multiFactorAuthClaim.d.ts

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

8 changes: 6 additions & 2 deletions lib/build/recipe/multifactorauth/recipe.d.ts

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

6 changes: 4 additions & 2 deletions lib/build/recipe/multifactorauth/types.d.ts

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useUserContext } from "../../../../../usercontext";
import { useOnMountAPICall } from "../../../../../utils";
import { SessionContext } from "../../../../session";
import Session from "../../../../session/recipe";
import MultiFactorAuth from "../../../recipe";
import FactorChooserTheme from "../../themes/factorChooser";
import { defaultTranslationsMultiFactorAuth } from "../../themes/translations";

Expand All @@ -46,17 +47,24 @@ export const FactorChooser: React.FC<Prop> = (props) => {
await redirectToAuth({ redirectBack: false, history: props.history });
}, [props.history]);

const fetchMFAInfo = useCallback(async () => {
if (sessionContext.loading === true) {
// This callback should only be called if the session is already loaded
throw new Error("Should never come here");
}
return await props.recipe.webJSRecipe.getMFAInfo({ userContext });
}, [props.recipe, sessionContext, redirectToAuthWithHistory, userContext]);
const fetchMFAInfo = useCallback(
async () => props.recipe.webJSRecipe.getMFAInfo({ userContext }),
[props.recipe, userContext]
);

const checkIsEmailVerified = useCallback(
const checkMFAInfo = useCallback(
async (mfaInfo: { factors: MFAFactorInfo }): Promise<void> => {
setMFAInfo(mfaInfo.factors);
const availableFactors = props.recipe
.getSecondaryFactors()
.filter(
({ id }) =>
mfaInfo.factors.isAllowedToSetup.includes(id) || mfaInfo.factors.isAlreadySetup.includes(id)
);
if (availableFactors.length === 1) {
return MultiFactorAuth.getInstanceOrThrow().redirectToFactor(availableFactors[0].id, props.history);
} else {
setMFAInfo(mfaInfo.factors);
}
},
[setMFAInfo]
);
Expand All @@ -72,7 +80,7 @@ export const FactorChooser: React.FC<Prop> = (props) => {
[redirectToAuthWithHistory]
);

useOnMountAPICall(fetchMFAInfo, checkIsEmailVerified, handleError, sessionContext.loading === false);
useOnMountAPICall(fetchMFAInfo, checkMFAInfo, handleError, sessionContext.loading === false);

const navigateToFactor = useCallback(
(factorId) => props.recipe.redirect({ action: "GO_TO_FACTOR", factorId }),
Expand All @@ -91,6 +99,9 @@ export const FactorChooser: React.FC<Prop> = (props) => {
const childProps = {
config: props.recipe.config,
};
const availableFactors = props.recipe
.getSecondaryFactors()
.filter(({ id }) => mfaInfo.isAllowedToSetup.includes(id) || mfaInfo.isAlreadySetup.includes(id));
return (
<ComponentOverrideContext.Provider value={recipeComponentOverrides}>
<FeatureWrapper
Expand All @@ -102,9 +113,7 @@ export const FactorChooser: React.FC<Prop> = (props) => {
<FactorChooserTheme
{...childProps}
mfaInfo={mfaInfo}
availableFactors={props.recipe.factorRedirectionInfo.filter(
({ id }) => mfaInfo.isAllowedToSetup.includes(id) || mfaInfo.isAlreadySetup.includes(id)
)}
availableFactors={availableFactors}
logout={signOut}
navigateToFactor={navigateToFactor}
/>
Expand Down
Loading

0 comments on commit ad99b5f

Please sign in to comment.