Skip to content

Commit

Permalink
feat!: make the mfa screens do success redirection if the next array…
Browse files Browse the repository at this point in the history
… is empty (#851)

* feat!: make the mfa screens do success redirection if the next array is empty

* feat: self-review fixes

* docs: update example apps

* chore: bump version and size limit
  • Loading branch information
porcellus authored Aug 23, 2024
1 parent 989f6b2 commit 7990896
Show file tree
Hide file tree
Showing 28 changed files with 547 additions and 222 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Breaking changes

- Changed `redirectToFactor` to accept an object instead of multiple arguments.
- Changed `redirectToFactorChooser` to accept an object instead of multiple arguments.
- Made MFA related screens do a success redirection if MFA is already completed and the `stepUp` query param is not set to `true`.
- `redirectToFactorChooser` now accepts a `stepUp` option to set the `stepUp` query param.
- `redirectToFactor` now accepts a `stepUp` option to set the `stepUp` query param.

## [0.45.1] - 2024-08-09

### Changes
Expand Down
8 changes: 6 additions & 2 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,13 @@ export function DashboardHelper({ redirectOnLogout, ...props } = {}) {
<a
className="goToFactorChooser"
onClick={() => {
return MultiFactorAuth.redirectToFactorChooser(true, undefined, props.history);
return MultiFactorAuth.redirectToFactorChooser({
redirectBack: true,
stepUp: true,
navigate: props.history,
});
}}>
MFA chooser
MFA chooser (step up)
</a>
</div>
);
Expand Down
8 changes: 6 additions & 2 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,13 @@ export function DashboardHelper({ redirectOnLogout, ...props } = {}) {
<a
className="goToFactorChooser"
onClick={() => {
return MultiFactorAuth.redirectToFactorChooser(true, undefined, props.history);
return MultiFactorAuth.redirectToFactorChooser({
redirectBack: true,
stepUp: true,
navigate: props.history,
});
}}>
MFA chooser
MFA chooser (step up)
</a>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.2.1",
"react-scripts": "5.0.1",
"supertokens-auth-react": "latest",
"supertokens-auth-react": "github:supertokens/supertokens-auth-react#feat/mfa_redirect",
"supertokens-web-js": "latest",
"typescript": "^4.8.2",
"web-vitals": "^2.1.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ export default function CallAPIView() {
}

async function goToPhoneSetup() {
await MultiFactorAuth.redirectToFactor(MultiFactorAuth.FactorIds.OTP_PHONE, true, true, navigate);
await MultiFactorAuth.redirectToFactor({
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
forceSetup: true,
redirectBack: true,
navigate,
});
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ export default function SelectPhone() {
if (res.status === 200) {
const loadedInfo = await res.clone().json();
if (loadedInfo.user.phoneNumbers.length === 0) {
await MultiFactorAuth.redirectToFactor(MultiFactorAuth.FactorIds.OTP_PHONE, true, false, nav);
await MultiFactorAuth.redirectToFactor({
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
forceSetup: true,
redirectBack: false,
navigate: nav,
});
} else if (loadedInfo.user.phoneNumbers.length === 1) {
await Passwordless.createCode({ phoneNumber: loadedInfo.user.phoneNumbers[0] });
await MultiFactorAuth.redirectToFactor(MultiFactorAuth.FactorIds.OTP_PHONE, false, false, nav);
await MultiFactorAuth.redirectToFactor({
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
redirectBack: false,
navigate: nav,
});
} else {
setUserInfo(loadedInfo);
}
Expand Down Expand Up @@ -65,12 +74,11 @@ export default function SelectPhone() {
hasOtherPhoneNumbers: true,
},
});
return MultiFactorAuth.redirectToFactor(
MultiFactorAuth.FactorIds.OTP_PHONE,
false,
false,
nav
);
return MultiFactorAuth.redirectToFactor({
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
redirectBack: false,
navigate: nav,
});
}
})
.catch(setError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export default function RecoveryCode() {
if (reset.data.status !== "OK") {
setError("Recovery code not found");
} else {
await MultiFactorAuth.redirectToFactor("totp", true, false, nav);
await MultiFactorAuth.redirectToFactor({
factorId: "totp",
forceSetup: true,
redirectBack: false,
navigate: nav,
});
}
}

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.

70 changes: 40 additions & 30 deletions lib/build/multifactorauth-shared2.js

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

46 changes: 19 additions & 27 deletions lib/build/multifactorauth.js

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

33 changes: 27 additions & 6 deletions lib/build/multifactorauthprebuiltui.js

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

Loading

0 comments on commit 7990896

Please sign in to comment.