diff --git a/apps/signup-form/src/Preview.stories.tsx b/apps/signup-form/src/Preview.stories.tsx index 3274bed9da..9463dcd5f0 100644 --- a/apps/signup-form/src/Preview.stories.tsx +++ b/apps/signup-form/src/Preview.stories.tsx @@ -45,6 +45,13 @@ const Preview: React.FC { + await new Promise((resolve) => { + setTimeout(resolve, 500); + }); + + return 'testtoken'; } }, t: i18n.t, diff --git a/apps/signup-form/src/components/pages/FormPage.tsx b/apps/signup-form/src/components/pages/FormPage.tsx index 608e04746c..453ae3c3f5 100644 --- a/apps/signup-form/src/components/pages/FormPage.tsx +++ b/apps/signup-form/src/components/pages/FormPage.tsx @@ -21,7 +21,8 @@ export const FormPage: React.FC = () => { setLoading(true); try { - await api.sendMagicLink({email, labels: options.labels}); + const integrityToken = await api.getIntegrityToken(); + await api.sendMagicLink({email, labels: options.labels, integrityToken}); if (minimal) { // Don't go to the success page, but show the success state in the form diff --git a/apps/signup-form/src/utils/api.tsx b/apps/signup-form/src/utils/api.tsx index 65dc51733f..4485c976c6 100644 --- a/apps/signup-form/src/utils/api.tsx +++ b/apps/signup-form/src/utils/api.tsx @@ -12,14 +12,31 @@ export const setupGhostApi = ({siteUrl}: {siteUrl: string}) => { } return { - sendMagicLink: async ({email, labels}: {email: string, labels: string[]}) => { + getIntegrityToken: async (): Promise => { + const url = endpointFor({type: 'members', resource: 'integrity-token'}); + + const response = await fetch(url, { + headers: { + 'app-pragma': 'no-cache', + 'x-ghost-version': '5.90' + } + }); + + if (response.status < 200 || response.status >= 300) { + throw new Error(response.statusText); + } + + return response.text(); + }, + sendMagicLink: async ({email, integrityToken, labels}: {email: string, labels: string[], integrityToken: string}) => { const url = endpointFor({type: 'members', resource: 'send-magic-link'}); const payload = JSON.stringify({ email, emailType: 'signup', labels, - urlHistory: getUrlHistory({siteUrl}) + urlHistory: getUrlHistory({siteUrl}), + integrityToken }); const response = await fetch(url, { diff --git a/apps/signup-form/test/utils/e2e.ts b/apps/signup-form/test/utils/e2e.ts index 92d3d54a9a..b8ac0e35da 100644 --- a/apps/signup-form/test/utils/e2e.ts +++ b/apps/signup-form/test/utils/e2e.ts @@ -65,5 +65,9 @@ export async function mockApi({page, status = 200}: {page: any, status?: number} await route.abort('addressunreachable'); }); + await page.route(`${MOCKED_SITE_URL}/members/api/integrity-token/`, async (route) => { + await route.fulfill('testtoken'); + }); + return lastApiRequest; }