Skip to content

Commit 57055cf

Browse files
fixes bug - sendEmail (#448)
* fixes bug * adds tests
1 parent 70b5ec1 commit 57055cf

File tree

9 files changed

+83
-6
lines changed

9 files changed

+83
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [12.1.2] - 2022-12-06
11+
12+
- Fixes issue where if sendEmail is overridden with a different email, it will reset that email.
13+
1014
## [12.1.1] - 2022-11-25
1115

1216
- Fixed an issue with importing the wrong recipe in the dashboard APIs

lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class BackwardCompatibilityService {
4343
if (user === undefined) {
4444
throw Error("this should never come here");
4545
}
46+
// we add this here cause the user may have overridden the sendEmail function
47+
// to change the input email and if we don't do this, the input email
48+
// will get reset by the getUserById call above.
49+
user.email = input.user.email;
4650
try {
4751
if (!this.isInServerlessEnv) {
4852
this.resetPasswordUsingTokenFeature

lib/build/version.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/version.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export default class BackwardCompatibilityService
6262
if (user === undefined) {
6363
throw Error("this should never come here");
6464
}
65+
// we add this here cause the user may have overridden the sendEmail function
66+
// to change the input email and if we don't do this, the input email
67+
// will get reset by the getUserById call above.
68+
user.email = input.user.email;
6569
try {
6670
if (!this.isInServerlessEnv) {
6771
this.resetPasswordUsingTokenFeature

lib/ts/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15-
export const version = "12.1.1";
15+
export const version = "12.1.2";
1616

1717
export const cdiSupported = ["2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15"];
1818

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "supertokens-node",
3-
"version": "12.1.1",
3+
"version": "12.1.2",
44
"description": "NodeJS driver for SuperTokens core",
55
"main": "index.js",
66
"scripts": {

test/emailpassword/emailDelivery.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,69 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js]
764764
assert(sendRawEmailCalled);
765765
assert.notStrictEqual(emailVerifyURL, undefined);
766766
});
767+
768+
it("test backward compatibility: reset password and sendEmail override", async function () {
769+
await startST();
770+
let email = undefined;
771+
let passwordResetURL = undefined;
772+
let timeJoined = undefined;
773+
STExpress.init({
774+
supertokens: {
775+
connectionURI: "http://localhost:8080",
776+
},
777+
appInfo: {
778+
apiDomain: "api.supertokens.io",
779+
appName: "SuperTokens",
780+
websiteDomain: "supertokens.io",
781+
},
782+
recipeList: [
783+
EmailPassword.init({
784+
emailDelivery: {
785+
override: (oI) => {
786+
return {
787+
...oI,
788+
sendEmail: async function (input) {
789+
input.user.email = "[email protected]";
790+
return oI.sendEmail(input);
791+
},
792+
};
793+
},
794+
},
795+
resetPasswordUsingTokenFeature: {
796+
createAndSendCustomEmail: async (input, passwordResetLink) => {
797+
email = input.email;
798+
passwordResetURL = passwordResetLink;
799+
timeJoined = input.timeJoined;
800+
},
801+
},
802+
}),
803+
Session.init(),
804+
],
805+
telemetry: false,
806+
});
807+
808+
const app = express();
809+
app.use(middleware());
810+
app.use(errorHandler());
811+
812+
await EmailPassword.signUp("[email protected]", "1234abcd");
813+
814+
await supertest(app)
815+
.post("/auth/user/password/reset/token")
816+
.set("rid", "emailpassword")
817+
.send({
818+
formFields: [
819+
{
820+
id: "email",
821+
822+
},
823+
],
824+
})
825+
.expect(200);
826+
827+
await delay(2);
828+
assert.strictEqual(email, "[email protected]");
829+
assert.notStrictEqual(passwordResetURL, undefined);
830+
assert.notStrictEqual(timeJoined, undefined);
831+
});
767832
});

0 commit comments

Comments
 (0)