Skip to content

Commit

Permalink
fix: firstFactors + test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Nov 6, 2023
1 parent a9ce3b5 commit 3deb3cd
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 9 deletions.
8 changes: 8 additions & 0 deletions lib/build/emailpassword-shared4.js

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

3 changes: 3 additions & 0 deletions lib/build/emailpassword.js

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

3 changes: 2 additions & 1 deletion lib/build/index2.js

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

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

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

8 changes: 8 additions & 0 deletions lib/build/thirdparty-shared.js

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

3 changes: 3 additions & 0 deletions lib/build/thirdparty.js

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

3 changes: 3 additions & 0 deletions lib/build/thirdpartyemailpassword.js

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

6 changes: 3 additions & 3 deletions lib/build/thirdpartypasswordless.js

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

9 changes: 9 additions & 0 deletions lib/ts/recipe/emailpassword/recipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

import EmailPasswordWebJS from "supertokens-web-js/recipe/emailpassword";
import NormalisedURLPath from "supertokens-web-js/utils/normalisedURLPath";
import { PostSuperTokensInitCallbacks } from "supertokens-web-js/utils/postSuperTokensInitCallbacks";

import { SSR_ERROR } from "../../constants";
import { isTest } from "../../utils";
import AuthRecipe from "../authRecipe";
import MultiFactorAuth from "../multifactorauth/recipe";

import { DEFAULT_RESET_PASSWORD_PATH } from "./constants";
import { getFunctionOverrides } from "./functionOverrides";
Expand Down Expand Up @@ -58,6 +60,13 @@ export default class EmailPassword extends AuthRecipe<
public readonly webJSRecipe: WebJSRecipeInterface<typeof EmailPasswordWebJS> = EmailPasswordWebJS
) {
super(config);

PostSuperTokensInitCallbacks.addPostInitCallback(() => {
const mfa = MultiFactorAuth.getInstance();
if (mfa !== undefined) {
mfa.addMFAFactors(["emailpassword"], []);
}
});
}

getDefaultRedirectionURL = async (context: GetRedirectionURLContext): Promise<string> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const FactorList = withOverride(
{availableFactors.map((factor) => (
<FactorOption
key={factor.id}
id={factor.id}
name={factor.name}
description={factor.description}
logo={factor.logo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ export const FactorOption = withOverride(
"MultiFactorAuthFactorOption",
function MultiFactorAuthFactorOption({
onClick,
id,
name,
description,
logo,
}: {
onClick: (() => void) | undefined;
id: string;
name: string;
description: string;
logo: FC;
}): JSX.Element {
const t = useTranslation();
return (
<a data-supertokens="factorChooserOption" onClick={onClick}>
<a data-supertokens={`factorChooserOption ${id}`} onClick={onClick}>
<div data-supertokens="factorLogo"> {logo({})}</div>
<div data-supertokens="factorOptionText">
<h6 data-supertokens="factorName">{t(name)}</h6>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function FactorChooserTheme(props: FactorChooserThemeProps): JSX.Element
if (props.availableFactors.length === 0) {
return (
<AccessDeniedScreen
useShadowDom={props.config.useShadowDom}
useShadowDom={false}
error={props.showBackButton ? t("MFA_NO_AVAILABLE_OPTIONS") : t("MFA_NO_AVAILABLE_OPTIONS_LOGIN")}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion lib/ts/recipe/recipeRouter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export abstract class RecipeRouter {
return componentMatchingRid;
}

if (mfaRecipe) {
// TODO: check if we need this whole defaultFirstFactors thing.
if (mfaRecipe && mfaRecipe.config.firstFactors !== undefined) {
return chooseComponentBasedOnFirstFactors(mfaRecipe.getFirstFactors(), routeComponents);
} else {
return defaultComp;
Expand Down
10 changes: 10 additions & 0 deletions lib/ts/recipe/thirdparty/recipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/

import ThirdpartyWebJS from "supertokens-web-js/recipe/thirdparty";
import { PostSuperTokensInitCallbacks } from "supertokens-web-js/utils/postSuperTokensInitCallbacks";

import { SSR_ERROR } from "../../constants";
import SuperTokens from "../../superTokens";
import { isTest } from "../../utils";
import AuthRecipe from "../authRecipe";
import MultiFactorAuth from "../multifactorauth/recipe";

import { getFunctionOverrides } from "./functionOverrides";
import { normaliseThirdPartyConfig } from "./utils";
Expand Down Expand Up @@ -58,6 +60,14 @@ export default class ThirdParty extends AuthRecipe<
if (SuperTokens.usesDynamicLoginMethods === false && config.signInAndUpFeature.providers.length === 0) {
throw new Error("ThirdParty signInAndUpFeature providers array cannot be empty.");
}

PostSuperTokensInitCallbacks.addPostInitCallback(() => {
const mfa = MultiFactorAuth.getInstance();
if (mfa !== undefined) {
mfa.addMFAFactors(["thirdparty"], []);
}
});

super(config);
}

Expand Down

0 comments on commit 3deb3cd

Please sign in to comment.