From 65d47f2be9a7a80e5c35eb756900e5c004c02bc1 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Mon, 13 May 2024 13:57:30 +0530 Subject: [PATCH] fixes to snippets --- v2/mfa/backend-setup.mdx | 2 ++ v2/mfa/email-sms-otp/otp-for-all-users.mdx | 4 ++-- v2/mfa/email-sms-otp/otp-for-opt-in-users.mdx | 6 +++--- v2/mfa/step-up-auth.mdx | 8 ++++---- v2/mfa/totp/totp-for-all-users.mdx | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/v2/mfa/backend-setup.mdx b/v2/mfa/backend-setup.mdx index 79cee71d5..1956a6361 100644 --- a/v2/mfa/backend-setup.mdx +++ b/v2/mfa/backend-setup.mdx @@ -162,6 +162,7 @@ For a multi tenancy setup, where each tenant can have a different set of first f ```tsx import Multitenancy from "supertokens-node/recipe/multitenancy"; +import MultiFactorAuth from "supertokens-node/recipe/multifactorauth" async function createNewTenant() { let resp = await Multitenancy.createOrUpdateTenant("customer1", { @@ -532,6 +533,7 @@ For a multi tenant setup, you can configure a list of secondary factors when cre ```tsx import Multitenancy from "supertokens-node/recipe/multitenancy"; +import MultiFactorAuth from "supertokens-node/recipe/multifactorauth" async function createNewTenant() { let resp = await Multitenancy.createOrUpdateTenant("customer1", { diff --git a/v2/mfa/email-sms-otp/otp-for-all-users.mdx b/v2/mfa/email-sms-otp/otp-for-all-users.mdx index d0d0c4cd5..49ffb0e34 100644 --- a/v2/mfa/email-sms-otp/otp-for-all-users.mdx +++ b/v2/mfa/email-sms-otp/otp-for-all-users.mdx @@ -86,7 +86,7 @@ supertokens.init({ firstFactors: [ MultiFactorAuth.FactorIds.EMAILPASSWORD, MultiFactorAuth.FactorIds.THIRDPARTY - ] + ], // highlight-start override: { functions: (originalImplementation) => { @@ -498,7 +498,7 @@ async function createNewTenant() { firstFactors: [ MultiFactorAuth.FactorIds.EMAILPASSWORD, MultiFactorAuth.FactorIds.THIRDPARTY - ] + ], requiredSecondaryFactors: [MultiFactorAuth.FactorIds.OTP_EMAIL] }); diff --git a/v2/mfa/email-sms-otp/otp-for-opt-in-users.mdx b/v2/mfa/email-sms-otp/otp-for-opt-in-users.mdx index 4d5e6b856..84fe5f53b 100644 --- a/v2/mfa/email-sms-otp/otp-for-opt-in-users.mdx +++ b/v2/mfa/email-sms-otp/otp-for-opt-in-users.mdx @@ -95,7 +95,7 @@ supertokens.init({ firstFactors: [ MultiFactorAuth.FactorIds.EMAILPASSWORD, MultiFactorAuth.FactorIds.THIRDPARTY - ] + ], // highlight-start override: { functions: (originalImplementation) => { @@ -425,7 +425,7 @@ supertokens.init({ firstFactors: [ MultiFactorAuth.FactorIds.EMAILPASSWORD, MultiFactorAuth.FactorIds.THIRDPARTY - ] + ], override: { functions: (originalImplementation) => { return { @@ -541,7 +541,7 @@ supertokens.init({ firstFactors: [ MultiFactorAuth.FactorIds.EMAILPASSWORD, MultiFactorAuth.FactorIds.THIRDPARTY - ] + ], // highlight-start override: { functions: (originalImplementation) => { diff --git a/v2/mfa/step-up-auth.mdx b/v2/mfa/step-up-auth.mdx index 471acfc28..5387fb6db 100644 --- a/v2/mfa/step-up-auth.mdx +++ b/v2/mfa/step-up-auth.mdx @@ -640,7 +640,7 @@ async function shouldLoadRoute(): Promise { // since all default claim validators have passed, we now check for if the user has finished TOTP // within the last 5 mins let mfaClaimValue = await Session.getClaimValue({ claim: MultiFactorAuthClaim }); - let totpCompletedTime = mfaClaimValue?.c[MultiFactorAuth.FactorIds.TOTP]; + let totpCompletedTime = mfaClaimValue?.c["totp"]; if (totpCompletedTime === undefined || totpCompletedTime < (DateProviderReference.getReferenceOrThrow().dateProvider.now() - 1000 * 60 * 5)) { // ths user needs to complete TOTP since it's been more than 5 mins since they completed it. return false; @@ -693,7 +693,7 @@ async function shouldLoadRoute(): Promise { // since all default claim validators have passed, we now check for if the user has finished TOTP // within the last 5 mins let mfaClaimValue = await Session.getClaimValue({ claim: MultiFactorAuthClaim }); - let totpCompletedTime = mfaClaimValue?.c[MultiFactorAuth.FactorIds.TOTP]; + let totpCompletedTime = mfaClaimValue?.c["totp"]; if (totpCompletedTime === undefined || totpCompletedTime < (DateProviderReference.getReferenceOrThrow().dateProvider.now() - 1000 * 60 * 5)) { // ths user needs to complete TOTP since it's been more than 5 mins since they completed it. return false; @@ -723,7 +723,7 @@ async function shouldLoadRoute(): Promise { // since all default claim validators have passed, we now check for if the user has finished TOTP // within the last 5 mins let mfaClaimValue = await supertokensSession.getClaimValue({ claim: supertokensMultiFactorAuth.MultiFactorAuthClaim }); - let totpCompletedTime = mfaClaimValue?.c[MultiFactorAuth.FactorIds.TOTP]; + let totpCompletedTime = mfaClaimValue?.c["totp"]; if (totpCompletedTime === undefined || totpCompletedTime < (supertokensDateProviderReference.DateProviderReference.getReferenceOrThrow().dateProvider.now() - 1000 * 60 * 5)) { // ths user needs to complete TOTP since it's been more than 5 mins since they completed it. return false; @@ -763,7 +763,7 @@ async function checkIfMFAIsCompleted() { let isMFACompleted: boolean = (await SuperTokens.getAccessTokenPayloadSecurely())["st-mfa"].v; if (isMFACompleted) { let completedFactors = (await SuperTokens.getAccessTokenPayloadSecurely())["st-mfa"].c; - if (completedFactors[MultiFactorAuth.FactorIds.TOTP] === undefined || completedFactors[MultiFactorAuth.FactorIds.TOTP] < (Date.now() - 1000*60*5)) { + if (completedFactors["totp"] === undefined || completedFactors["totp"] < (Date.now() - 1000*60*5)) { // user has not finished TOTP MFA in the last 5 minutes } } else { diff --git a/v2/mfa/totp/totp-for-all-users.mdx b/v2/mfa/totp/totp-for-all-users.mdx index 86ad62929..33b83bbd4 100644 --- a/v2/mfa/totp/totp-for-all-users.mdx +++ b/v2/mfa/totp/totp-for-all-users.mdx @@ -826,7 +826,7 @@ async function createNewTenant() { firstFactors: [ MultiFactorAuth.FactorIds.EMAILPASSWORD, MultiFactorAuth.FactorIds.THIRDPARTY - ] + ], requiredSecondaryFactors: [MultiFactorAuth.FactorIds.OTP_EMAIL] });