@@ -66,21 +66,16 @@ const UserRoles = require("supertokens-node/recipe/userroles");
6666const MultitenancyRaw = require ( "supertokens-node/lib/build/recipe/multitenancy/recipe" ) . default ;
6767const Multitenancy = require ( "supertokens-node/lib/build/recipe/multitenancy/index" ) ;
6868
69- const AccountLinkingRaw = require ( "supertokens-node/lib/build/recipe/accountlinking/recipe" ) . default ;
70- const AccountLinking = require ( "supertokens-node/recipe/accountlinking" ) ;
69+ let AccountLinking , AccountLinkingRaw , accountLinkingSupported ;
70+ try {
71+ AccountLinkingRaw = require ( "supertokens-node/lib/build/recipe/accountlinking/recipe" ) . default ;
72+ AccountLinking = require ( "supertokens-node/recipe/accountlinking" ) ;
73+ accountLinkingSupported = true ;
74+ } catch ( ex ) {
75+ accountLinkingSupported = false ;
76+ }
7177
7278const UserMetadataRaw = require ( "supertokens-node/lib/build/recipe/usermetadata/recipe" ) . default ;
73- const UserMetadata = require ( "supertokens-node/recipe/usermetadata" ) ;
74-
75- const MultiFactorAuthRaw = require ( "supertokens-node/lib/build/recipe/multifactorauth/recipe" ) . default ;
76- const MultiFactorAuth = require ( "supertokens-node/recipe/multifactorauth" ) ;
77-
78- const TOTPRaw = require ( "supertokens-node/lib/build/recipe/totp/recipe" ) . default ;
79- const TOTP = require ( "supertokens-node/recipe/totp" ) ;
80-
81- const OTPAuth = require ( "otpauth" ) ;
82-
83- let generalErrorSupported ;
8479
8580if ( maxVersion ( nodeSDKVersion , "9.9.9" ) === "9.9.9" ) {
8681 // General error is only supported by 10.0.0 and above
@@ -196,10 +191,11 @@ function initST({
196191 UserRolesRaw . reset ( ) ;
197192 PasswordlessRaw . reset ( ) ;
198193 MultitenancyRaw . reset ( ) ;
199- AccountLinkingRaw . reset ( ) ;
194+
195+ if ( accountLinkingSupported ) {
196+ AccountLinkingRaw . reset ( ) ;
197+ }
200198 UserMetadataRaw . reset ( ) ;
201- MultiFactorAuthRaw . reset ( ) ;
202- TOTPRaw . reset ( ) ;
203199
204200 EmailVerificationRaw . reset ( ) ;
205201 EmailPasswordRaw . reset ( ) ;
@@ -670,7 +666,7 @@ function initST({
670666 ...accountLinkingConfig ,
671667 } ;
672668
673- if ( accountLinkingConfig . enabled ) {
669+ if ( accountLinkingSupported && accountLinkingConfig . enabled ) {
674670 recipeList . push ( [
675671 "accountlinking" ,
676672 AccountLinking . init ( {
@@ -680,74 +676,6 @@ function initST({
680676 } ) ,
681677 ] ) ;
682678 }
683- recipeList . push ( [
684- "multifactorauth" ,
685- MultiFactorAuth . init ( {
686- firstFactors : mfaInfo . firstFactors ,
687- override : {
688- functions : ( oI ) => ( {
689- ...oI ,
690- getFactorsSetupForUser : async ( input ) => {
691- const res = await oI . getFactorsSetupForUser ( input ) ;
692- if ( mfaInfo ?. alreadySetup ) {
693- return mfaInfo . alreadySetup ;
694- }
695- return res ;
696- } ,
697- assertAllowedToSetupFactorElseThrowInvalidClaimError : async ( input ) => {
698- if ( mfaInfo ?. allowedToSetup ) {
699- if ( ! mfaInfo . allowedToSetup . includes ( input . factorId ) ) {
700- throw new Session . Error ( {
701- type : "INVALID_CLAIMS" ,
702- message : "INVALID_CLAIMS" ,
703- payload : [
704- {
705- id : "test" ,
706- reason : "test override" ,
707- } ,
708- ] ,
709- } ) ;
710- }
711- } else {
712- await oI . assertAllowedToSetupFactorElseThrowInvalidClaimError ( input ) ;
713- }
714- } ,
715- getMFARequirementsForAuth : async ( input ) => {
716- const res = await oI . getMFARequirementsForAuth ( input ) ;
717- if ( mfaInfo ?. requirements ) {
718- return mfaInfo . requirements ;
719- }
720- return res ;
721- } ,
722- } ) ,
723- apis : ( oI ) => ( {
724- ...oI ,
725- resyncSessionAndFetchMFAInfoPUT : async ( input ) => {
726- const res = await oI . resyncSessionAndFetchMFAInfoPUT ( input ) ;
727-
728- if ( res . status === "OK" ) {
729- if ( mfaInfo . alreadySetup ) {
730- res . factors . alreadySetup = [ ...mfaInfo . alreadySetup ] ;
731- }
732- }
733- if ( mfaInfo . noContacts ) {
734- res . emails = { } ;
735- res . phoneNumbers = { } ;
736- }
737- return res ;
738- } ,
739- } ) ,
740- } ,
741- } ) ,
742- ] ) ;
743-
744- recipeList . push ( [
745- "totp" ,
746- TOTP . init ( {
747- defaultPeriod : 1 ,
748- defaultSkew : 30 ,
749- } ) ,
750- ] ) ;
751679
752680 SuperTokens . init ( {
753681 appInfo : {
@@ -859,7 +787,7 @@ app.get("/sessioninfo", verifySession(), async (req, res, next) => {
859787 res . send ( {
860788 sessionHandle : session . getHandle ( ) ,
861789 userId : session . getUserId ( ) ,
862- recipeUserId : session . getRecipeUserId ( ) . getAsString ( ) ,
790+ recipeUserId : accountLinkingSupported ? session . getRecipeUserId ( ) . getAsString ( ) : session . getUserId ( ) ,
863791 accessTokenPayload,
864792 sessionData,
865793 } ) ;
@@ -869,6 +797,11 @@ app.get("/sessioninfo", verifySession(), async (req, res, next) => {
869797} ) ;
870798
871799app . post ( "/deleteUser" , async ( req , res ) => {
800+ if ( ! accountLinkingSupported ) {
801+ const user = await EmailPassword . getUserByEmail ( "public" , req . body . email ) ;
802+ return res . send ( await SuperTokens . deleteUser ( user . id ) ) ;
803+ }
804+
872805 const users = await SuperTokens . listUsersByAccountInfo ( "public" , req . body ) ;
873806 res . send ( await SuperTokens . deleteUser ( users [ 0 ] . id ) ) ;
874807} ) ;
@@ -903,8 +836,8 @@ app.post("/changeEmail", async (req, res) => {
903836
904837app . get ( "/unverifyEmail" , verifySession ( ) , async ( req , res ) => {
905838 let session = req . session ;
906- await EmailVerification . unverifyEmail ( session . getRecipeUserId ( ) ) ;
907- await session . fetchAndSetClaim ( EmailVerification . EmailVerificationClaim , { } ) ;
839+ await EmailVerification . unverifyEmail ( accountLinkingSupported ? session . getRecipeUserId ( ) : session . getUserId ( ) ) ;
840+ await session . fetchAndSetClaim ( EmailVerification . EmailVerificationClaim ) ;
908841 res . send ( { status : "OK" } ) ;
909842} ) ;
910843
@@ -940,22 +873,6 @@ app.post(
940873 }
941874) ;
942875
943- app . post ( "/completeFactor" , verifySession ( ) , async ( req , res ) => {
944- let session = req . session ;
945-
946- await MultiFactorAuth . markFactorAsCompleteInSession ( session , req . body . id ) ;
947-
948- res . send ( { status : "OK" } ) ;
949- } ) ;
950-
951- app . post ( "/addRequiredFactor" , verifySession ( ) , async ( req , res ) => {
952- let session = req . session ;
953-
954- await MultiFactorAuth . addToRequiredSecondaryFactorsForUser ( session . getUserId ( ) , req . body . factorId ) ;
955-
956- res . send ( { status : "OK" } ) ;
957- } ) ;
958-
959876app . post ( "/mergeIntoAccessTokenPayload" , verifySession ( ) , async ( req , res ) => {
960877 let session = req . session ;
961878
@@ -972,18 +889,10 @@ app.get("/token", async (_, res) => {
972889
973890app . post ( "/setupTenant" , async ( req , res ) => {
974891 const { tenantId, loginMethods, coreConfig } = req . body ;
975- let firstFactors = [ ] ;
976- if ( loginMethods . emailPassword ?. enabled === true ) {
977- firstFactors . push ( "emailpassword" ) ;
978- }
979- if ( loginMethods . passwordless ?. enabled === true ) {
980- firstFactors . push ( "otp-phone" , "otp-email" , "link-phone" , "link-email" ) ;
981- }
982- if ( loginMethods . thirdParty ?. enabled === true ) {
983- firstFactors . push ( "thirdparty" ) ;
984- }
985892 let coreResp = await Multitenancy . createOrUpdateTenant ( tenantId , {
986- firstFactors,
893+ emailPasswordEnabled : loginMethods . emailPassword ?. enabled === true ,
894+ thirdPartyEnabled : loginMethods . thirdParty ?. enabled === true ,
895+ passwordlessEnabled : loginMethods . passwordless ?. enabled === true ,
987896 coreConfig,
988897 } ) ;
989898
@@ -1020,10 +929,6 @@ app.get("/test/getDevice", (req, res) => {
1020929 res . send ( deviceStore . get ( req . query . preAuthSessionId ) ) ;
1021930} ) ;
1022931
1023- app . post ( "/test/getTOTPCode" , ( req , res ) => {
1024- res . send ( JSON . stringify ( { totp : new OTPAuth . TOTP ( { secret : req . body . secret , digits : 6 , period : 1 } ) . generate ( ) } ) ) ;
1025- } ) ;
1026-
1027932app . get ( "/test/featureFlags" , ( req , res ) => {
1028933 const available = [ ] ;
1029934
@@ -1038,10 +943,10 @@ app.get("/test/featureFlags", (req, res) => {
1038943 available . push ( "userroles" ) ;
1039944 available . push ( "multitenancy" ) ;
1040945 available . push ( "multitenancyManagementEndpoints" ) ;
1041- available . push ( "accountlinking" ) ;
1042- available . push ( "mfa" ) ;
946+ if ( accountLinkingSupported ) {
947+ available . push ( "accountlinking" ) ;
948+ }
1043949 available . push ( "recipeConfig" ) ;
1044- available . push ( "oauth2" ) ;
1045950 available . push ( "accountlinking-fixes" ) ;
1046951
1047952 res . send ( {
0 commit comments