From 9f64bcc3b637ff3692be2ae1e96ffbb42e0bdc08 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Tue, 12 Mar 2024 14:17:12 +0530 Subject: [PATCH] fixes more snippets --- v2/mfa/frontend-setup.mdx | 17 +++++++++-------- v2/mfa/step-up-auth.mdx | 28 +++++++++++++++------------- 2 files changed, 24 insertions(+), 21 deletions(-) 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 } } + } } ```