Skip to content

Commit 423fb83

Browse files
authored
fix: adds check for thirdpartyemailpassword to test server (#916)
1 parent 8434721 commit 423fb83

File tree

1 file changed

+126
-109
lines changed

1 file changed

+126
-109
lines changed

test/server/index.js

Lines changed: 126 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ let { default: SuperTokensRaw } = require("supertokens-node/lib/build/supertoken
1818
const { default: EmailVerificationRaw } = require("supertokens-node/lib/build/recipe/emailverification/recipe");
1919
const { default: EmailPasswordRaw } = require("supertokens-node/lib/build/recipe/emailpassword/recipe");
2020
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");
2421
const { default: SessionRaw } = require("supertokens-node/lib/build/recipe/session/recipe");
2522
let Session = require("supertokens-node/recipe/session");
2623
let EmailPassword = require("supertokens-node/recipe/emailpassword");
2724
let ThirdParty = require("supertokens-node/recipe/thirdparty");
2825
let EmailVerification = require("supertokens-node/recipe/emailverification");
29-
let ThirdPartyEmailPassword = require("supertokens-node/recipe/thirdpartyemailpassword");
3026
let { verifySession } = require("supertokens-node/recipe/session/framework/express");
3127
let { middleware, errorHandler } = require("supertokens-node/framework/express");
3228
let express = require("express");
@@ -61,6 +57,18 @@ try {
6157
thirdPartyPasswordlessSupported = false;
6258
}
6359

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+
6472
const UserRolesRaw = require("supertokens-node/lib/build/recipe/userroles/recipe").default;
6573
const UserRoles = require("supertokens-node/recipe/userroles");
6674

@@ -205,13 +213,16 @@ function initST({
205213
EmailVerificationRaw.reset();
206214
EmailPasswordRaw.reset();
207215
ThirdPartyRaw.reset();
208-
ThirdPartyEmailPasswordRaw.reset();
209216
SessionRaw.reset();
210217

211218
if (thirdPartyPasswordlessSupported) {
212219
ThirdPartyPasswordlessRaw.reset();
213220
}
214221

222+
if (thirdPartyEmailPasswordSupported) {
223+
ThirdPartyEmailPasswordRaw.reset();
224+
}
225+
215226
SuperTokensRaw.reset();
216227
}
217228

@@ -381,109 +392,6 @@ function initST({
381392
},
382393
}),
383394
],
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-
],
487395
[
488396
"session",
489397
Session.init({
@@ -649,6 +557,112 @@ function initST({
649557
]);
650558
}
651559

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+
652666
recipeList.push(["userroles", UserRoles.init()]);
653667

654668
recipeList.push([
@@ -1029,7 +1043,10 @@ app.get("/test/featureFlags", (req, res) => {
10291043
available.push("thirdpartypasswordless");
10301044
}
10311045

1032-
available.push("thirdpartyemailpassword");
1046+
if (thirdPartyEmailPasswordSupported) {
1047+
available.push("thirdpartyemailpassword");
1048+
}
1049+
10331050
available.push("generalerror");
10341051
available.push("userroles");
10351052
available.push("multitenancy");

0 commit comments

Comments
 (0)