Skip to content

Commit

Permalink
fixes more snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Mar 12, 2024
1 parent 9b1ae56 commit 9f64bcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
17 changes: 9 additions & 8 deletions v2/mfa/frontend-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,19 @@ fileprivate class ViewController: UIViewController {
```dart
import 'package:supertokens_flutter/supertokens.dart';
Future<void> isAllMFACompleted() async {
var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely();
Future<bool> isAllMFACompleted() async {
var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely();
if (accessTokenPayload.containsKey("st-mfa")) {
Map<String, dynamic> mfaObject = accessTokenPayload["st-mfa"];
if (accessTokenPayload.containsKey("st-mfa")) {
Map<String, dynamic> mfaObject = accessTokenPayload["st-mfa"];
if (mfaObject.containsKey("v")) {
Boolean isMFACompleted = mfaObject["v"];
if (mfaObject.containsKey("v")) {
bool isMFACompleted = mfaObject["v"];
return isMFACompleted;
}
return isMFACompleted;
}
}
return false; // Return false if "st-mfa" is not present or "v" is not found
}
```

Expand Down
28 changes: 15 additions & 13 deletions v2/mfa/step-up-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -836,25 +836,27 @@ fileprivate class ViewController: UIViewController {
import 'package:supertokens_flutter/supertokens.dart';
Future<void> checkIfMFAIsCompleted() async {
var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely();
var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely();
if (accessTokenPayload.containsKey("st-mfa")) {
Map<String, dynamic> mfaObject = accessTokenPayload["st-mfa"];
if (accessTokenPayload.containsKey("st-mfa")) {
Map<String, dynamic> mfaObject = accessTokenPayload["st-mfa"];
if (mfaObject.containsKey("v")) {
bool isMFACompleted = mfaObject["v"];
if (mfaObject.containsKey("v")) {
bool isMFACompleted = mfaObject["v"] as bool; // Casting to bool
if (isMFACompleted) {
// All required factors for MFA have been completed
Map<String, dynamic> mfaCompletedFactors = mfaObject["c"];
if (mfaCompletedFactors["totp"] == null || mfaCompletedFactors["totp"] < (DateTime.now().millisecondsSinceEpoch - 1000*60*5)) {
// user has not finished TOTP MFA in the last 5 minutes
}
} else {
// You can check the `c` object from ["st-mfa"] prop to see which factors have been completed by the user
if (isMFACompleted) {
// All required factors for MFA have been completed
Map<String, dynamic> mfaCompletedFactors = mfaObject["c"];
if (mfaCompletedFactors["totp"] == null ||
mfaCompletedFactors["totp"] <
(DateTime.now().millisecondsSinceEpoch - 1000 * 60 * 5)) {
// user has not finished TOTP MFA in the last 5 minutes
}
} else {
// You can check the `c` object from ["st-mfa"] prop to see which factors have been completed by the user
}
}
}
}
```

Expand Down

0 comments on commit 9f64bcc

Please sign in to comment.