@@ -18,15 +18,11 @@ let { default: SuperTokensRaw } = require("supertokens-node/lib/build/supertoken
18
18
const { default : EmailVerificationRaw } = require ( "supertokens-node/lib/build/recipe/emailverification/recipe" ) ;
19
19
const { default : EmailPasswordRaw } = require ( "supertokens-node/lib/build/recipe/emailpassword/recipe" ) ;
20
20
const { default : ThirdPartyRaw } = require ( "supertokens-node/lib/build/recipe/thirdparty/recipe" ) ;
21
- const {
22
- default : ThirdPartyEmailPasswordRaw ,
23
- } = require ( "supertokens-node/lib/build/recipe/thirdpartyemailpassword/recipe" ) ;
24
21
const { default : SessionRaw } = require ( "supertokens-node/lib/build/recipe/session/recipe" ) ;
25
22
let Session = require ( "supertokens-node/recipe/session" ) ;
26
23
let EmailPassword = require ( "supertokens-node/recipe/emailpassword" ) ;
27
24
let ThirdParty = require ( "supertokens-node/recipe/thirdparty" ) ;
28
25
let EmailVerification = require ( "supertokens-node/recipe/emailverification" ) ;
29
- let ThirdPartyEmailPassword = require ( "supertokens-node/recipe/thirdpartyemailpassword" ) ;
30
26
let { verifySession } = require ( "supertokens-node/recipe/session/framework/express" ) ;
31
27
let { middleware, errorHandler } = require ( "supertokens-node/framework/express" ) ;
32
28
let express = require ( "express" ) ;
61
57
thirdPartyPasswordlessSupported = false ;
62
58
}
63
59
60
+ let thirdPartyEmailPasswordSupported ;
61
+ let ThirdPartyEmailPasswordRaw ;
62
+ let ThirdPartyEmailPassword ;
63
+
64
+ try {
65
+ ThirdPartyEmailPasswordRaw = require ( "supertokens-node/lib/build/recipe/thirdpartyemailpassword/recipe" ) . default ;
66
+ ThirdPartyEmailPassword = require ( "supertokens-node/recipe/thirdpartyemailpassword" ) ;
67
+ thirdPartyEmailPasswordSupported = true ;
68
+ } catch ( ex ) {
69
+ thirdPartyEmailPasswordSupported = false ;
70
+ }
71
+
64
72
const UserRolesRaw = require ( "supertokens-node/lib/build/recipe/userroles/recipe" ) . default ;
65
73
const UserRoles = require ( "supertokens-node/recipe/userroles" ) ;
66
74
@@ -205,13 +213,16 @@ function initST({
205
213
EmailVerificationRaw . reset ( ) ;
206
214
EmailPasswordRaw . reset ( ) ;
207
215
ThirdPartyRaw . reset ( ) ;
208
- ThirdPartyEmailPasswordRaw . reset ( ) ;
209
216
SessionRaw . reset ( ) ;
210
217
211
218
if ( thirdPartyPasswordlessSupported ) {
212
219
ThirdPartyPasswordlessRaw . reset ( ) ;
213
220
}
214
221
222
+ if ( thirdPartyEmailPasswordSupported ) {
223
+ ThirdPartyEmailPasswordRaw . reset ( ) ;
224
+ }
225
+
215
226
SuperTokensRaw . reset ( ) ;
216
227
}
217
228
@@ -381,109 +392,6 @@ function initST({
381
392
} ,
382
393
} ) ,
383
394
] ,
384
- [
385
- "thirdpartyemailpassword" ,
386
- ThirdPartyEmailPassword . init ( {
387
- signUpFeature : {
388
- formFields,
389
- } ,
390
- emailDelivery : {
391
- override : ( oI ) => {
392
- return {
393
- ...oI ,
394
- sendEmail : async ( input ) => {
395
- console . log ( input . passwordResetLink ) ;
396
- latestURLWithToken = input . passwordResetLink ;
397
- } ,
398
- } ;
399
- } ,
400
- } ,
401
- providers :
402
- enabledProviders !== undefined
403
- ? fullProviderList . filter ( ( config ) => enabledProviders . includes ( config . config ) )
404
- : fullProviderList ,
405
- override : {
406
- apis : ( originalImplementation ) => {
407
- return {
408
- ...originalImplementation ,
409
- emailPasswordSignUpPOST : async function ( input ) {
410
- let body = await input . options . req . getJSONBody ( ) ;
411
- if ( body . generalError === true ) {
412
- return {
413
- status : "GENERAL_ERROR" ,
414
- message : "general error from API sign up" ,
415
- } ;
416
- }
417
-
418
- return originalImplementation . emailPasswordSignUpPOST ( input ) ;
419
- } ,
420
- passwordResetPOST : async function ( input ) {
421
- let body = await input . options . req . getJSONBody ( ) ;
422
- if ( body . generalError === true ) {
423
- return {
424
- status : "GENERAL_ERROR" ,
425
- message : "general error from API reset password consume" ,
426
- } ;
427
- }
428
- return originalImplementation . passwordResetPOST ( input ) ;
429
- } ,
430
- generatePasswordResetTokenPOST : async function ( input ) {
431
- let body = await input . options . req . getJSONBody ( ) ;
432
- if ( body . generalError === true ) {
433
- return {
434
- status : "GENERAL_ERROR" ,
435
- message : "general error from API reset password" ,
436
- } ;
437
- }
438
- return originalImplementation . generatePasswordResetTokenPOST ( input ) ;
439
- } ,
440
- emailPasswordEmailExistsGET : async function ( input ) {
441
- let generalError = input . options . req . getKeyValueFromQuery ( "generalError" ) ;
442
- if ( generalError === "true" ) {
443
- return {
444
- status : "GENERAL_ERROR" ,
445
- message : "general error from API email exists" ,
446
- } ;
447
- }
448
- return originalImplementation . emailPasswordEmailExistsGET ( input ) ;
449
- } ,
450
- emailPasswordSignInPOST : async function ( input ) {
451
- let body = await input . options . req . getJSONBody ( ) ;
452
- if ( body . generalError === true ) {
453
- return {
454
- status : "GENERAL_ERROR" ,
455
- message : "general error from API sign in" ,
456
- } ;
457
- }
458
- return originalImplementation . emailPasswordSignInPOST ( input ) ;
459
- } ,
460
- authorisationUrlGET : async function ( input ) {
461
- let generalErrorFromQuery = input . options . req . getKeyValueFromQuery ( "generalError" ) ;
462
- if ( generalErrorFromQuery === "true" ) {
463
- return {
464
- status : "GENERAL_ERROR" ,
465
- message : "general error from API authorisation url get" ,
466
- } ;
467
- }
468
-
469
- return originalImplementation . authorisationUrlGET ( input ) ;
470
- } ,
471
- thirdPartySignInUpPOST : async function ( input ) {
472
- let body = await input . options . req . getJSONBody ( ) ;
473
- if ( body . generalError === true ) {
474
- return {
475
- status : "GENERAL_ERROR" ,
476
- message : "general error from API sign in up" ,
477
- } ;
478
- }
479
-
480
- return originalImplementation . thirdPartySignInUpPOST ( input ) ;
481
- } ,
482
- } ;
483
- } ,
484
- } ,
485
- } ) ,
486
- ] ,
487
395
[
488
396
"session" ,
489
397
Session . init ( {
@@ -649,6 +557,112 @@ function initST({
649
557
] ) ;
650
558
}
651
559
560
+ if ( thirdPartyEmailPasswordSupported ) {
561
+ recipeList . push ( [
562
+ "thirdpartyemailpassword" ,
563
+ ThirdPartyEmailPassword . init ( {
564
+ signUpFeature : {
565
+ formFields,
566
+ } ,
567
+ emailDelivery : {
568
+ override : ( oI ) => {
569
+ return {
570
+ ...oI ,
571
+ sendEmail : async ( input ) => {
572
+ console . log ( input . passwordResetLink ) ;
573
+ latestURLWithToken = input . passwordResetLink ;
574
+ } ,
575
+ } ;
576
+ } ,
577
+ } ,
578
+ providers :
579
+ enabledProviders !== undefined
580
+ ? fullProviderList . filter ( ( config ) => enabledProviders . includes ( config . config ) )
581
+ : fullProviderList ,
582
+ override : {
583
+ apis : ( originalImplementation ) => {
584
+ return {
585
+ ...originalImplementation ,
586
+ emailPasswordSignUpPOST : async function ( input ) {
587
+ let body = await input . options . req . getJSONBody ( ) ;
588
+ if ( body . generalError === true ) {
589
+ return {
590
+ status : "GENERAL_ERROR" ,
591
+ message : "general error from API sign up" ,
592
+ } ;
593
+ }
594
+
595
+ return originalImplementation . emailPasswordSignUpPOST ( input ) ;
596
+ } ,
597
+ passwordResetPOST : async function ( input ) {
598
+ let body = await input . options . req . getJSONBody ( ) ;
599
+ if ( body . generalError === true ) {
600
+ return {
601
+ status : "GENERAL_ERROR" ,
602
+ message : "general error from API reset password consume" ,
603
+ } ;
604
+ }
605
+ return originalImplementation . passwordResetPOST ( input ) ;
606
+ } ,
607
+ generatePasswordResetTokenPOST : async function ( input ) {
608
+ let body = await input . options . req . getJSONBody ( ) ;
609
+ if ( body . generalError === true ) {
610
+ return {
611
+ status : "GENERAL_ERROR" ,
612
+ message : "general error from API reset password" ,
613
+ } ;
614
+ }
615
+ return originalImplementation . generatePasswordResetTokenPOST ( input ) ;
616
+ } ,
617
+ emailPasswordEmailExistsGET : async function ( input ) {
618
+ let generalError = input . options . req . getKeyValueFromQuery ( "generalError" ) ;
619
+ if ( generalError === "true" ) {
620
+ return {
621
+ status : "GENERAL_ERROR" ,
622
+ message : "general error from API email exists" ,
623
+ } ;
624
+ }
625
+ return originalImplementation . emailPasswordEmailExistsGET ( input ) ;
626
+ } ,
627
+ emailPasswordSignInPOST : async function ( input ) {
628
+ let body = await input . options . req . getJSONBody ( ) ;
629
+ if ( body . generalError === true ) {
630
+ return {
631
+ status : "GENERAL_ERROR" ,
632
+ message : "general error from API sign in" ,
633
+ } ;
634
+ }
635
+ return originalImplementation . emailPasswordSignInPOST ( input ) ;
636
+ } ,
637
+ authorisationUrlGET : async function ( input ) {
638
+ let generalErrorFromQuery = input . options . req . getKeyValueFromQuery ( "generalError" ) ;
639
+ if ( generalErrorFromQuery === "true" ) {
640
+ return {
641
+ status : "GENERAL_ERROR" ,
642
+ message : "general error from API authorisation url get" ,
643
+ } ;
644
+ }
645
+
646
+ return originalImplementation . authorisationUrlGET ( input ) ;
647
+ } ,
648
+ thirdPartySignInUpPOST : async function ( input ) {
649
+ let body = await input . options . req . getJSONBody ( ) ;
650
+ if ( body . generalError === true ) {
651
+ return {
652
+ status : "GENERAL_ERROR" ,
653
+ message : "general error from API sign in up" ,
654
+ } ;
655
+ }
656
+
657
+ return originalImplementation . thirdPartySignInUpPOST ( input ) ;
658
+ } ,
659
+ } ;
660
+ } ,
661
+ } ,
662
+ } ) ,
663
+ ] ) ;
664
+ }
665
+
652
666
recipeList . push ( [ "userroles" , UserRoles . init ( ) ] ) ;
653
667
654
668
recipeList . push ( [
@@ -1029,7 +1043,10 @@ app.get("/test/featureFlags", (req, res) => {
1029
1043
available . push ( "thirdpartypasswordless" ) ;
1030
1044
}
1031
1045
1032
- available . push ( "thirdpartyemailpassword" ) ;
1046
+ if ( thirdPartyEmailPasswordSupported ) {
1047
+ available . push ( "thirdpartyemailpassword" ) ;
1048
+ }
1049
+
1033
1050
available . push ( "generalerror" ) ;
1034
1051
available . push ( "userroles" ) ;
1035
1052
available . push ( "multitenancy" ) ;
0 commit comments