diff --git a/package.json b/package.json index a96fcef..74c04db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@prefabs.tech/saas", - "version": "0.29.1", + "version": "0.29.2", "private": true, "repository": { "type": "git", diff --git a/packages/fastify/package.json b/packages/fastify/package.json index d807679..92cecf2 100644 --- a/packages/fastify/package.json +++ b/packages/fastify/package.json @@ -1,6 +1,6 @@ { "name": "@prefabs.tech/saas-fastify", - "version": "0.29.1", + "version": "0.29.2", "description": "saas plugin for fastify", "homepage": "https://github.com/prefabs-tech/saas/tree/main/packages/fastify#readme", "repository": { diff --git a/packages/fastify/src/supertokens/recipes/third-party-email-password/__test__/emailPasswordSignUp.test.ts b/packages/fastify/src/supertokens/recipes/third-party-email-password/__test__/emailPasswordSignUp.test.ts new file mode 100644 index 0000000..9707899 --- /dev/null +++ b/packages/fastify/src/supertokens/recipes/third-party-email-password/__test__/emailPasswordSignUp.test.ts @@ -0,0 +1,72 @@ +import type { FastifyInstance } from "fastify"; +import type { RecipeInterface } from "supertokens-node/recipe/thirdpartyemailpassword"; + +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const sendEmailMock = vi.fn(); + +vi.mock("@prefabs.tech/fastify-user", () => ({ + areRolesExist: vi.fn().mockResolvedValue(true), + getUserService: vi.fn(), + sendEmail: (...arguments_: unknown[]) => sendEmailMock(...arguments_), + verifyEmail: vi.fn(), +})); + +// Imported after the mock so the override picks up the mocked sendEmail. +const { default: emailPasswordSignUp } = await import("../emailPasswordSignUp"); + +const accountId = "76948988-1313-4ff5-9138-3dd3a3c95c70_"; +const cleanEmail = "user@example.com"; + +const buildFastify = () => + ({ + config: { + user: { + supertokens: { + sendUserAlreadyExistsWarning: true, + }, + }, + }, + log: { + error: vi.fn(), + }, + slonik: {}, + }) as unknown as FastifyInstance; + +const buildOriginalImplementation = () => + ({ + emailPasswordSignUp: vi.fn().mockResolvedValue({ + status: "EMAIL_ALREADY_EXISTS_ERROR", + }), + }) as unknown as RecipeInterface; + +describe("emailPasswordSignUp duplicate email warning", () => { + beforeEach(() => { + sendEmailMock.mockClear(); + }); + + it("sends the warning with the unprefixed email in templateData", async () => { + const fastify = buildFastify(); + const handler = emailPasswordSignUp(buildOriginalImplementation(), fastify); + + await handler({ + email: cleanEmail, + password: "password", + tenantId: "public", + userContext: { + authEmailPrefix: accountId, + }, + } as Parameters[0]); + + expect(sendEmailMock).toHaveBeenCalledTimes(1); + + const payload = sendEmailMock.mock.calls[0][0]; + + // Body renders {{emailId}} verbatim, so it must be the clean email. + expect(payload.templateData.emailId).toBe(cleanEmail); + expect(payload.templateData.emailId).not.toContain(accountId); + + // Recipient is also the clean email. + expect(payload.to).toBe(cleanEmail); + }); +}); diff --git a/packages/fastify/src/supertokens/recipes/third-party-email-password/emailPasswordSignUp.ts b/packages/fastify/src/supertokens/recipes/third-party-email-password/emailPasswordSignUp.ts index e14e03a..f308044 100644 --- a/packages/fastify/src/supertokens/recipes/third-party-email-password/emailPasswordSignUp.ts +++ b/packages/fastify/src/supertokens/recipes/third-party-email-password/emailPasswordSignUp.ts @@ -155,7 +155,7 @@ const emailPasswordSignUp = ( config.user.emailOverrides?.duplicateEmail?.subject || "Duplicate Email Registration", templateData: { - emailId: input.email, + emailId: originalEmail, }, templateName: config.user.emailOverrides?.duplicateEmail?.templateName || diff --git a/packages/react/package.json b/packages/react/package.json index 4e664c7..85adc2b 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@prefabs.tech/saas-react", - "version": "0.29.1", + "version": "0.29.2", "description": "Saas plugin for react", "type": "module", "exports": { diff --git a/packages/vue/package.json b/packages/vue/package.json index 86fb9af..6735487 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -1,6 +1,6 @@ { "name": "@prefabs.tech/saas-vue", - "version": "0.29.1", + "version": "0.29.2", "description": "Saas plugin for vue", "type": "module", "exports": {