From b6f4657ddffe19b6a479543b386cc1d1538bf0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mih=C3=A1ly=20Lengyel?= Date: Mon, 12 Aug 2024 01:06:58 +0200 Subject: [PATCH 1/2] fix: improve error messages when the authpage has issues covering all factors (#846) * fix: improve error messages when the authpage has issues covering all factors * fix: extend error message --- CHANGELOG.md | 6 ++ lib/build/genericComponentOverrideContext.js | 2 +- lib/build/index2.js | 67 +++++++++++++++---- lib/build/version.d.ts | 2 +- .../components/feature/authPage/authPage.tsx | 30 ++++++++- lib/ts/version.ts | 2 +- package-lock.json | 4 +- package.json | 2 +- 8 files changed, 95 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6d2c361..829e1c38e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [0.45.1] - 2024-08-09 + +### Changes + +- Now we only update the session context if the object changes by value. This optimization should help reduce unnecessary re-renders. + ## [0.45.0] - 2024-07-31 ### Breaking changes diff --git a/lib/build/genericComponentOverrideContext.js b/lib/build/genericComponentOverrideContext.js index 072ba9845..af29a1581 100644 --- a/lib/build/genericComponentOverrideContext.js +++ b/lib/build/genericComponentOverrideContext.js @@ -265,7 +265,7 @@ var SSR_ERROR = * License for the specific language governing permissions and limitations * under the License. */ -var package_version = "0.45.0"; +var package_version = "0.45.1"; /* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. * diff --git a/lib/build/index2.js b/lib/build/index2.js index dfaa0a44a..43d688fc1 100644 --- a/lib/build/index2.js +++ b/lib/build/index2.js @@ -1122,7 +1122,7 @@ function buildAndSetChildProps( setComponentListInfo, abort ) { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e; return genericComponentOverrideContext.__awaiter(this, void 0, void 0, function () { var authRecipesInited, firstFactors, @@ -1134,14 +1134,22 @@ function buildAndSetChildProps( _i, recipeRouters_1, ui, - _e, + _f, authComps_1, a, preloadRes, partialAuthComps, - selectedComponents; - return genericComponentOverrideContext.__generator(this, function (_f) { - switch (_f.label) { + selectedComponents, + availableFactors, + _g, + partialAuthComps_1, + comp, + _h, + _j, + id, + source; + return genericComponentOverrideContext.__generator(this, function (_k) { + switch (_k.label) { case 0: authRecipesInited = genericComponentOverrideContext.SuperTokens.getInstanceOrThrow().recipeList.filter(function ( @@ -1194,6 +1202,9 @@ function buildAndSetChildProps( ); } } + if (firstFactors.length === 0) { + throw new Error("There are no enabled factors to show"); + } if (firstFactors.includes(types.FactorIds.THIRDPARTY)) { thirdPartyPreBuiltUI = recipeRouters.find(function (r) { return r.recipeInstance.recipeID === types.FactorIds.THIRDPARTY; @@ -1211,6 +1222,11 @@ function buildAndSetChildProps( firstFactors = firstFactors.filter(function (f) { return f !== types.FactorIds.THIRDPARTY; }); + if (firstFactors.length === 0) { + throw new Error( + "The only enabled first factor is thirdparty, but no providers were defined. Please define at least one provider." + ); + } } } } @@ -1228,15 +1244,15 @@ function buildAndSetChildProps( ui = recipeRouters_1[_i]; authComps.push.apply(authComps, ui.getAuthComponents()); } - (_e = 0), (authComps_1 = authComps); - _f.label = 1; + (_f = 0), (authComps_1 = authComps); + _k.label = 1; case 1: - if (!(_e < authComps_1.length)) return [3 /*break*/, 4]; - a = authComps_1[_e]; + if (!(_f < authComps_1.length)) return [3 /*break*/, 4]; + a = authComps_1[_f]; if (!(a.type === "FULL_PAGE")) return [3 /*break*/, 3]; return [4 /*yield*/, a.preloadInfoAndRunChecks(firstFactors, userContext)]; case 2: - preloadRes = _f.sent(); + preloadRes = _k.sent(); // We skip setting if the auth page unmounted while we were checking // if we should show any full page comps if (abort.aborted) { @@ -1255,9 +1271,9 @@ function buildAndSetChildProps( }); return [2 /*return*/]; } - _f.label = 3; + _k.label = 3; case 3: - _e++; + _f++; return [3 /*break*/, 1]; case 4: if (abort.aborted) { @@ -1287,7 +1303,32 @@ function buildAndSetChildProps( }); selectedComponents = utils.selectComponentsToCoverAllFirstFactors(partialAuthComps, firstFactors); if (selectedComponents === undefined) { - throw new Error("Couldn't cover all first factors"); + availableFactors = new Set(); + for (_g = 0, partialAuthComps_1 = partialAuthComps; _g < partialAuthComps_1.length; _g++) { + comp = partialAuthComps_1[_g]; + for (_h = 0, _j = comp.factorIds; _h < _j.length; _h++) { + id = _j[_h]; + availableFactors.add(id); + } + } + source = + factorListState !== undefined + ? "local state or props" + : (loadedDynamicLoginMethods === null || loadedDynamicLoginMethods === void 0 + ? void 0 + : loadedDynamicLoginMethods.firstFactors) !== undefined + ? "dynamic tenant configuration" + : ((_e = recipe.MultiFactorAuth.getInstance()) === null || _e === void 0 + ? void 0 + : _e.config.firstFactors) !== undefined + ? "the config passed to the MFA recipe" + : "all recipes initialized"; + throw new Error( + "Couldn't cover all first factors: " + .concat(firstFactors.join(", "), " (from ") + .concat(source, "), available components: ") + .concat(Array.from(availableFactors).join(", ")) + ); } setComponentListInfo({ authComponents: selectedComponents diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index 3d96e3ccd..50c8e3518 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1 +1 @@ -export declare const package_version = "0.45.0"; +export declare const package_version = "0.45.1"; diff --git a/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx b/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx index 31c403458..c15b11c1c 100644 --- a/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx +++ b/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx @@ -354,6 +354,10 @@ async function buildAndSetChildProps( } } + if (firstFactors.length === 0) { + throw new Error("There are no enabled factors to show"); + } + if (firstFactors.includes(FactorIds.THIRDPARTY)) { // we get the thirdparty recipe here like this, because importing the recipe here would heavily increase the bundle size of many recipes const thirdPartyPreBuiltUI = recipeRouters.find((r) => r.recipeInstance.recipeID === FactorIds.THIRDPARTY); @@ -368,6 +372,11 @@ async function buildAndSetChildProps( (!SuperTokens.usesDynamicLoginMethods || loadedDynamicLoginMethods!.thirdparty.providers.length === 0) ) { firstFactors = firstFactors.filter((f) => f !== FactorIds.THIRDPARTY); + if (firstFactors.length === 0) { + throw new Error( + "The only enabled first factor is thirdparty, but no providers were defined. Please define at least one provider." + ); + } } } } @@ -435,7 +444,26 @@ async function buildAndSetChildProps( const selectedComponents = selectComponentsToCoverAllFirstFactors(partialAuthComps, firstFactors); if (selectedComponents === undefined) { - throw new Error("Couldn't cover all first factors"); + const availableFactors = new Set(); + for (const comp of partialAuthComps) { + for (const id of comp.factorIds) { + availableFactors.add(id); + } + } + const source = + factorListState !== undefined + ? "local state or props" + : loadedDynamicLoginMethods?.firstFactors !== undefined + ? "dynamic tenant configuration" + : MultiFactorAuth.getInstance()?.config.firstFactors !== undefined + ? "the config passed to the MFA recipe" + : "all recipes initialized"; + + throw new Error( + `Couldn't cover all first factors: ${firstFactors.join( + ", " + )} (from ${source}), available components: ${Array.from(availableFactors).join(", ")}` + ); } setComponentListInfo({ diff --git a/lib/ts/version.ts b/lib/ts/version.ts index b8da732d8..93c89bd80 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,4 +12,4 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const package_version = "0.45.0"; +export const package_version = "0.45.1"; diff --git a/package-lock.json b/package-lock.json index 3063dbddf..02ba0dbe6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-auth-react", - "version": "0.45.0", + "version": "0.45.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "supertokens-auth-react", - "version": "0.45.0", + "version": "0.45.1", "license": "Apache-2.0", "dependencies": { "intl-tel-input": "^17.0.19", diff --git a/package.json b/package.json index f4113257a..47a3eb9f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-auth-react", - "version": "0.45.0", + "version": "0.45.1", "description": "ReactJS SDK that provides login functionality with SuperTokens.", "main": "./index.js", "engines": { From 4372b66bf72e5522149798a9cb05b7097e7b2dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mih=C3=A1ly=20Lengyel?= Date: Mon, 12 Aug 2024 01:13:35 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Revert=20"fix:=20improve=20error=20messages?= =?UTF-8?q?=20when=20the=20authpage=20has=20issues=20covering=20all?= =?UTF-8?q?=E2=80=A6"=20(#848)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b6f4657ddffe19b6a479543b386cc1d1538bf0f4. --- CHANGELOG.md | 6 -- lib/build/genericComponentOverrideContext.js | 2 +- lib/build/index2.js | 67 ++++--------------- lib/build/version.d.ts | 2 +- .../components/feature/authPage/authPage.tsx | 30 +-------- lib/ts/version.ts | 2 +- package-lock.json | 4 +- package.json | 2 +- 8 files changed, 20 insertions(+), 95 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 829e1c38e..ad6d2c361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] -## [0.45.1] - 2024-08-09 - -### Changes - -- Now we only update the session context if the object changes by value. This optimization should help reduce unnecessary re-renders. - ## [0.45.0] - 2024-07-31 ### Breaking changes diff --git a/lib/build/genericComponentOverrideContext.js b/lib/build/genericComponentOverrideContext.js index af29a1581..072ba9845 100644 --- a/lib/build/genericComponentOverrideContext.js +++ b/lib/build/genericComponentOverrideContext.js @@ -265,7 +265,7 @@ var SSR_ERROR = * License for the specific language governing permissions and limitations * under the License. */ -var package_version = "0.45.1"; +var package_version = "0.45.0"; /* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. * diff --git a/lib/build/index2.js b/lib/build/index2.js index 43d688fc1..dfaa0a44a 100644 --- a/lib/build/index2.js +++ b/lib/build/index2.js @@ -1122,7 +1122,7 @@ function buildAndSetChildProps( setComponentListInfo, abort ) { - var _a, _b, _c, _d, _e; + var _a, _b, _c, _d; return genericComponentOverrideContext.__awaiter(this, void 0, void 0, function () { var authRecipesInited, firstFactors, @@ -1134,22 +1134,14 @@ function buildAndSetChildProps( _i, recipeRouters_1, ui, - _f, + _e, authComps_1, a, preloadRes, partialAuthComps, - selectedComponents, - availableFactors, - _g, - partialAuthComps_1, - comp, - _h, - _j, - id, - source; - return genericComponentOverrideContext.__generator(this, function (_k) { - switch (_k.label) { + selectedComponents; + return genericComponentOverrideContext.__generator(this, function (_f) { + switch (_f.label) { case 0: authRecipesInited = genericComponentOverrideContext.SuperTokens.getInstanceOrThrow().recipeList.filter(function ( @@ -1202,9 +1194,6 @@ function buildAndSetChildProps( ); } } - if (firstFactors.length === 0) { - throw new Error("There are no enabled factors to show"); - } if (firstFactors.includes(types.FactorIds.THIRDPARTY)) { thirdPartyPreBuiltUI = recipeRouters.find(function (r) { return r.recipeInstance.recipeID === types.FactorIds.THIRDPARTY; @@ -1222,11 +1211,6 @@ function buildAndSetChildProps( firstFactors = firstFactors.filter(function (f) { return f !== types.FactorIds.THIRDPARTY; }); - if (firstFactors.length === 0) { - throw new Error( - "The only enabled first factor is thirdparty, but no providers were defined. Please define at least one provider." - ); - } } } } @@ -1244,15 +1228,15 @@ function buildAndSetChildProps( ui = recipeRouters_1[_i]; authComps.push.apply(authComps, ui.getAuthComponents()); } - (_f = 0), (authComps_1 = authComps); - _k.label = 1; + (_e = 0), (authComps_1 = authComps); + _f.label = 1; case 1: - if (!(_f < authComps_1.length)) return [3 /*break*/, 4]; - a = authComps_1[_f]; + if (!(_e < authComps_1.length)) return [3 /*break*/, 4]; + a = authComps_1[_e]; if (!(a.type === "FULL_PAGE")) return [3 /*break*/, 3]; return [4 /*yield*/, a.preloadInfoAndRunChecks(firstFactors, userContext)]; case 2: - preloadRes = _k.sent(); + preloadRes = _f.sent(); // We skip setting if the auth page unmounted while we were checking // if we should show any full page comps if (abort.aborted) { @@ -1271,9 +1255,9 @@ function buildAndSetChildProps( }); return [2 /*return*/]; } - _k.label = 3; + _f.label = 3; case 3: - _f++; + _e++; return [3 /*break*/, 1]; case 4: if (abort.aborted) { @@ -1303,32 +1287,7 @@ function buildAndSetChildProps( }); selectedComponents = utils.selectComponentsToCoverAllFirstFactors(partialAuthComps, firstFactors); if (selectedComponents === undefined) { - availableFactors = new Set(); - for (_g = 0, partialAuthComps_1 = partialAuthComps; _g < partialAuthComps_1.length; _g++) { - comp = partialAuthComps_1[_g]; - for (_h = 0, _j = comp.factorIds; _h < _j.length; _h++) { - id = _j[_h]; - availableFactors.add(id); - } - } - source = - factorListState !== undefined - ? "local state or props" - : (loadedDynamicLoginMethods === null || loadedDynamicLoginMethods === void 0 - ? void 0 - : loadedDynamicLoginMethods.firstFactors) !== undefined - ? "dynamic tenant configuration" - : ((_e = recipe.MultiFactorAuth.getInstance()) === null || _e === void 0 - ? void 0 - : _e.config.firstFactors) !== undefined - ? "the config passed to the MFA recipe" - : "all recipes initialized"; - throw new Error( - "Couldn't cover all first factors: " - .concat(firstFactors.join(", "), " (from ") - .concat(source, "), available components: ") - .concat(Array.from(availableFactors).join(", ")) - ); + throw new Error("Couldn't cover all first factors"); } setComponentListInfo({ authComponents: selectedComponents diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index 50c8e3518..3d96e3ccd 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1 +1 @@ -export declare const package_version = "0.45.1"; +export declare const package_version = "0.45.0"; diff --git a/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx b/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx index c15b11c1c..31c403458 100644 --- a/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx +++ b/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx @@ -354,10 +354,6 @@ async function buildAndSetChildProps( } } - if (firstFactors.length === 0) { - throw new Error("There are no enabled factors to show"); - } - if (firstFactors.includes(FactorIds.THIRDPARTY)) { // we get the thirdparty recipe here like this, because importing the recipe here would heavily increase the bundle size of many recipes const thirdPartyPreBuiltUI = recipeRouters.find((r) => r.recipeInstance.recipeID === FactorIds.THIRDPARTY); @@ -372,11 +368,6 @@ async function buildAndSetChildProps( (!SuperTokens.usesDynamicLoginMethods || loadedDynamicLoginMethods!.thirdparty.providers.length === 0) ) { firstFactors = firstFactors.filter((f) => f !== FactorIds.THIRDPARTY); - if (firstFactors.length === 0) { - throw new Error( - "The only enabled first factor is thirdparty, but no providers were defined. Please define at least one provider." - ); - } } } } @@ -444,26 +435,7 @@ async function buildAndSetChildProps( const selectedComponents = selectComponentsToCoverAllFirstFactors(partialAuthComps, firstFactors); if (selectedComponents === undefined) { - const availableFactors = new Set(); - for (const comp of partialAuthComps) { - for (const id of comp.factorIds) { - availableFactors.add(id); - } - } - const source = - factorListState !== undefined - ? "local state or props" - : loadedDynamicLoginMethods?.firstFactors !== undefined - ? "dynamic tenant configuration" - : MultiFactorAuth.getInstance()?.config.firstFactors !== undefined - ? "the config passed to the MFA recipe" - : "all recipes initialized"; - - throw new Error( - `Couldn't cover all first factors: ${firstFactors.join( - ", " - )} (from ${source}), available components: ${Array.from(availableFactors).join(", ")}` - ); + throw new Error("Couldn't cover all first factors"); } setComponentListInfo({ diff --git a/lib/ts/version.ts b/lib/ts/version.ts index 93c89bd80..b8da732d8 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,4 +12,4 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const package_version = "0.45.1"; +export const package_version = "0.45.0"; diff --git a/package-lock.json b/package-lock.json index 02ba0dbe6..3063dbddf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-auth-react", - "version": "0.45.1", + "version": "0.45.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "supertokens-auth-react", - "version": "0.45.1", + "version": "0.45.0", "license": "Apache-2.0", "dependencies": { "intl-tel-input": "^17.0.19", diff --git a/package.json b/package.json index 47a3eb9f5..f4113257a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-auth-react", - "version": "0.45.1", + "version": "0.45.0", "description": "ReactJS SDK that provides login functionality with SuperTokens.", "main": "./index.js", "engines": {