Skip to content

Commit 27e6541

Browse files
authored
fix: improve firstfactor error msg (#849)
* fix: improve error messages when the authpage has issues covering all factors * fix: extend error message
1 parent 15f42ce commit 27e6541

File tree

8 files changed

+95
-20
lines changed

8 files changed

+95
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.45.1] - 2024-08-09
11+
12+
### Changes
13+
14+
- Now we only update the session context if the object changes by value. This optimization should help reduce unnecessary re-renders.
15+
1016
## [0.45.0] - 2024-07-31
1117

1218
### Breaking changes

lib/build/genericComponentOverrideContext.js

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

lib/build/index2.js

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

lib/build/version.d.ts

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

lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ async function buildAndSetChildProps(
354354
}
355355
}
356356

357+
if (firstFactors.length === 0) {
358+
throw new Error("There are no enabled factors to show");
359+
}
360+
357361
if (firstFactors.includes(FactorIds.THIRDPARTY)) {
358362
// we get the thirdparty recipe here like this, because importing the recipe here would heavily increase the bundle size of many recipes
359363
const thirdPartyPreBuiltUI = recipeRouters.find((r) => r.recipeInstance.recipeID === FactorIds.THIRDPARTY);
@@ -368,6 +372,11 @@ async function buildAndSetChildProps(
368372
(!SuperTokens.usesDynamicLoginMethods || loadedDynamicLoginMethods!.thirdparty.providers.length === 0)
369373
) {
370374
firstFactors = firstFactors.filter((f) => f !== FactorIds.THIRDPARTY);
375+
if (firstFactors.length === 0) {
376+
throw new Error(
377+
"The only enabled first factor is thirdparty, but no providers were defined. Please define at least one provider."
378+
);
379+
}
371380
}
372381
}
373382
}
@@ -435,7 +444,26 @@ async function buildAndSetChildProps(
435444
const selectedComponents = selectComponentsToCoverAllFirstFactors(partialAuthComps, firstFactors);
436445

437446
if (selectedComponents === undefined) {
438-
throw new Error("Couldn't cover all first factors");
447+
const availableFactors = new Set();
448+
for (const comp of partialAuthComps) {
449+
for (const id of comp.factorIds) {
450+
availableFactors.add(id);
451+
}
452+
}
453+
const source =
454+
factorListState !== undefined
455+
? "local state or props"
456+
: loadedDynamicLoginMethods?.firstFactors !== undefined
457+
? "dynamic tenant configuration"
458+
: MultiFactorAuth.getInstance()?.config.firstFactors !== undefined
459+
? "the config passed to the MFA recipe"
460+
: "all recipes initialized";
461+
462+
throw new Error(
463+
`Couldn't cover all first factors: ${firstFactors.join(
464+
", "
465+
)} (from ${source}), available components: ${Array.from(availableFactors).join(", ")}`
466+
);
439467
}
440468

441469
setComponentListInfo({

lib/ts/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15-
export const package_version = "0.45.0";
15+
export const package_version = "0.45.1";

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "supertokens-auth-react",
3-
"version": "0.45.0",
3+
"version": "0.45.1",
44
"description": "ReactJS SDK that provides login functionality with SuperTokens.",
55
"main": "./index.js",
66
"engines": {

0 commit comments

Comments
 (0)