Skip to content

Commit f4f1d3a

Browse files
committed
feat(multifactorauth): add getSecondaryFactors to multifactor recipe method and enhance error handling for plugin version mismatches and duplicates
1 parent e2d4f3e commit f4f1d3a

File tree

9 files changed

+54
-10
lines changed

9 files changed

+54
-10
lines changed

lib/build/genericComponentOverrideContext.js

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/multifactorauth.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/recipe/multifactorauth/index.d.ts

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/thirdparty.js

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/recipe/multifactorauth/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ export default class Wrapper {
8787
});
8888
}
8989

90+
static getSecondaryFactors(input: { userContext?: UserContext }) {
91+
return MultiFactorAuthRecipe.getInstanceOrThrow().getSecondaryFactors(
92+
getNormalisedUserContext(input.userContext)
93+
);
94+
}
95+
9096
static ComponentsOverrideProvider = RecipeComponentsOverrideContextProvider;
9197
}
9298

9399
const init = Wrapper.init;
94100
const resyncSessionAndFetchMFAInfo = Wrapper.resyncSessionAndFetchMFAInfo;
95101
const redirectToFactor = Wrapper.redirectToFactor;
96102
const redirectToFactorChooser = Wrapper.redirectToFactorChooser;
103+
const getSecondaryFactors = Wrapper.getSecondaryFactors;
97104
const MultiFactorAuthComponentsOverrideProvider = Wrapper.ComponentsOverrideProvider;
98105
const MultiFactorAuthClaim = MultiFactorAuthRecipe.MultiFactorAuthClaim;
99106

@@ -102,6 +109,7 @@ export {
102109
resyncSessionAndFetchMFAInfo,
103110
redirectToFactor,
104111
redirectToFactorChooser,
112+
getSecondaryFactors,
105113
MultiFactorAuthComponentsOverrideProvider,
106114
GetRedirectionURLContext,
107115
PreAPIHookContext as PreAPIHookContext,

lib/ts/recipe/session/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ export default class SessionAPIWrapper {
110110
}
111111

112112
static ComponentsOverrideProvider = RecipeComponentsOverrideContextProvider;
113-
114-
// todo add exports like this to all recipes
115-
// static internal = {
116-
// getInstanceOrThrow: Session.getInstanceOrThrow.bind(Session),
117-
// };
118113
}
119114

120115
const useSessionContext = SessionAPIWrapper.useSessionContext;

lib/ts/recipe/thirdparty/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export default class Wrapper {
121121
});
122122
}
123123

124-
// todo figure out how to make use of dynamic providers
125124
static getProviders(): { id: string; name: string }[] {
126125
return ThirdParty.getInstanceOrThrow().config.signInAndUpFeature.providers.map((provider) => ({
127126
id: provider.id,

lib/ts/superTokens.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ export default class SuperTokens {
213213
: [plugin.compatibleAuthReactSDKVersions];
214214
if (!versionContraints.includes(package_version)) {
215215
// TODO: better checks
216-
throw new Error("Plugin version mismatch");
216+
throw new Error(
217+
`Plugin version mismatch. Version ${package_version} not found in compatible versions: ${versionContraints.join(
218+
", "
219+
)}`
220+
);
217221
}
218222
}
219223
if (plugin.dependencies) {
@@ -233,6 +237,13 @@ export default class SuperTokens {
233237
}
234238
}
235239

240+
const duplicatePluginIds = finalPluginList.filter((plugin, index) =>
241+
finalPluginList.some((elem, idx) => elem.id === plugin.id && idx !== index)
242+
);
243+
if (duplicatePluginIds.length > 0) {
244+
throw new Error(`Duplicate plugin IDs: ${duplicatePluginIds.map((plugin) => plugin.id).join(", ")}`);
245+
}
246+
236247
for (const plugin of finalPluginList) {
237248
if (plugin.config) {
238249
// prevent override of appInfo

lib/ts/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ export type PluginRouteHandler = {
524524

525525
// TODO: this should probably derive from the web-js version
526526
export type SuperTokensPlugin = {
527-
id: string; // TODO: validate that no two plugins have the same id
527+
id: string;
528528
version?: string;
529529
compatibleAuthReactSDKVersions?: string | string[]; // match the syntax of the engines field in package.json
530530
compatibleWebJSSDKVersions?: string | string[]; // match the syntax of the engines field in package.json

0 commit comments

Comments
 (0)