Skip to content

Commit

Permalink
fix: improve firstfactor error msg (#849)
Browse files Browse the repository at this point in the history
* fix: improve error messages when the authpage has issues covering all factors

* fix: extend error message
  • Loading branch information
porcellus authored Aug 12, 2024
1 parent 15f42ce commit 27e6541
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/build/genericComponentOverrideContext.js

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

67 changes: 54 additions & 13 deletions lib/build/index2.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/version.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 @@ -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);
Expand All @@ -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."
);
}
}
}
}
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 27e6541

Please sign in to comment.