Skip to content

Commit 7990896

Browse files
authored
feat!: make the mfa screens do success redirection if the next array 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
1 parent 989f6b2 commit 7990896

File tree

28 files changed

+547
-222
lines changed

28 files changed

+547
-222
lines changed

CHANGELOG.md

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

88
## [unreleased]
99

10+
### Breaking changes
11+
12+
- Changed `redirectToFactor` to accept an object instead of multiple arguments.
13+
- Changed `redirectToFactorChooser` to accept an object instead of multiple arguments.
14+
- Made MFA related screens do a success redirection if MFA is already completed and the `stepUp` query param is not set to `true`.
15+
- `redirectToFactorChooser` now accepts a `stepUp` option to set the `stepUp` query param.
16+
- `redirectToFactor` now accepts a `stepUp` option to set the `stepUp` query param.
17+
1018
## [0.45.1] - 2024-08-09
1119

1220
### Changes

examples/for-tests-react-16/src/App.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,13 @@ export function DashboardHelper({ redirectOnLogout, ...props } = {}) {
514514
<a
515515
className="goToFactorChooser"
516516
onClick={() => {
517-
return MultiFactorAuth.redirectToFactorChooser(true, undefined, props.history);
517+
return MultiFactorAuth.redirectToFactorChooser({
518+
redirectBack: true,
519+
stepUp: true,
520+
navigate: props.history,
521+
});
518522
}}>
519-
MFA chooser
523+
MFA chooser (step up)
520524
</a>
521525
</div>
522526
);

examples/for-tests/src/App.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,13 @@ export function DashboardHelper({ redirectOnLogout, ...props } = {}) {
686686
<a
687687
className="goToFactorChooser"
688688
onClick={() => {
689-
return MultiFactorAuth.redirectToFactorChooser(true, undefined, props.history);
689+
return MultiFactorAuth.redirectToFactorChooser({
690+
redirectBack: true,
691+
stepUp: true,
692+
navigate: props.history,
693+
});
690694
}}>
691-
MFA chooser
695+
MFA chooser (step up)
692696
</a>
693697
</div>
694698
);

examples/with-multifactorauth-phone-chooser/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react-dom": "^18.2.0",
1616
"react-router-dom": "^6.2.1",
1717
"react-scripts": "5.0.1",
18-
"supertokens-auth-react": "latest",
18+
"supertokens-auth-react": "github:supertokens/supertokens-auth-react#feat/mfa_redirect",
1919
"supertokens-web-js": "latest",
2020
"typescript": "^4.8.2",
2121
"web-vitals": "^2.1.4"

examples/with-multifactorauth-phone-chooser/frontend/src/Home/CallAPIView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export default function CallAPIView() {
1313
}
1414

1515
async function goToPhoneSetup() {
16-
await MultiFactorAuth.redirectToFactor(MultiFactorAuth.FactorIds.OTP_PHONE, true, true, navigate);
16+
await MultiFactorAuth.redirectToFactor({
17+
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
18+
forceSetup: true,
19+
redirectBack: true,
20+
navigate,
21+
});
1722
}
1823

1924
return (

examples/with-multifactorauth-phone-chooser/frontend/src/SelectPhone/index.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ export default function SelectPhone() {
1616
if (res.status === 200) {
1717
const loadedInfo = await res.clone().json();
1818
if (loadedInfo.user.phoneNumbers.length === 0) {
19-
await MultiFactorAuth.redirectToFactor(MultiFactorAuth.FactorIds.OTP_PHONE, true, false, nav);
19+
await MultiFactorAuth.redirectToFactor({
20+
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
21+
forceSetup: true,
22+
redirectBack: false,
23+
navigate: nav,
24+
});
2025
} else if (loadedInfo.user.phoneNumbers.length === 1) {
2126
await Passwordless.createCode({ phoneNumber: loadedInfo.user.phoneNumbers[0] });
22-
await MultiFactorAuth.redirectToFactor(MultiFactorAuth.FactorIds.OTP_PHONE, false, false, nav);
27+
await MultiFactorAuth.redirectToFactor({
28+
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
29+
redirectBack: false,
30+
navigate: nav,
31+
});
2332
} else {
2433
setUserInfo(loadedInfo);
2534
}
@@ -65,12 +74,11 @@ export default function SelectPhone() {
6574
hasOtherPhoneNumbers: true,
6675
},
6776
});
68-
return MultiFactorAuth.redirectToFactor(
69-
MultiFactorAuth.FactorIds.OTP_PHONE,
70-
false,
71-
false,
72-
nav
73-
);
77+
return MultiFactorAuth.redirectToFactor({
78+
factorId: MultiFactorAuth.FactorIds.OTP_PHONE,
79+
redirectBack: false,
80+
navigate: nav,
81+
});
7482
}
7583
})
7684
.catch(setError);

examples/with-multifactorauth-recovery-codes/frontend/src/RecoveryCode/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export default function RecoveryCode() {
1717
if (reset.data.status !== "OK") {
1818
setError("Recovery code not found");
1919
} else {
20-
await MultiFactorAuth.redirectToFactor("totp", true, false, nav);
20+
await MultiFactorAuth.redirectToFactor({
21+
factorId: "totp",
22+
forceSetup: true,
23+
redirectBack: false,
24+
navigate: nav,
25+
});
2126
}
2227
}
2328

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/multifactorauth-shared2.js

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

lib/build/multifactorauth.js

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

0 commit comments

Comments
 (0)