diff --git a/v2/mfa/frontend-setup.mdx b/v2/mfa/frontend-setup.mdx index da273ba9f..746c2fdf0 100644 --- a/v2/mfa/frontend-setup.mdx +++ b/v2/mfa/frontend-setup.mdx @@ -480,18 +480,19 @@ fileprivate class ViewController: UIViewController { ```dart import 'package:supertokens_flutter/supertokens.dart'; -Future isAllMFACompleted() async { - var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely(); +Future isAllMFACompleted() async { + var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely(); - if (accessTokenPayload.containsKey("st-mfa")) { - Map mfaObject = accessTokenPayload["st-mfa"]; + if (accessTokenPayload.containsKey("st-mfa")) { + Map 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 } ``` diff --git a/v2/mfa/step-up-auth.mdx b/v2/mfa/step-up-auth.mdx index f7bd28d51..1b3849108 100644 --- a/v2/mfa/step-up-auth.mdx +++ b/v2/mfa/step-up-auth.mdx @@ -836,25 +836,27 @@ fileprivate class ViewController: UIViewController { import 'package:supertokens_flutter/supertokens.dart'; Future checkIfMFAIsCompleted() async { - var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely(); + var accessTokenPayload = await SuperTokens.getAccessTokenPayloadSecurely(); - if (accessTokenPayload.containsKey("st-mfa")) { - Map mfaObject = accessTokenPayload["st-mfa"]; + if (accessTokenPayload.containsKey("st-mfa")) { + Map 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 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 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 } } + } } ```