Added integrity token to signup-form package

ref KTLO-1
This commit is contained in:
Sam Lord 2024-08-22 18:57:24 +01:00 committed by Sam Lord
parent ef4f79370f
commit ebc87002ce
4 changed files with 32 additions and 3 deletions

View File

@ -45,6 +45,13 @@ const Preview: React.FC<SignupFormOptions & {
} }
return; return;
},
getIntegrityToken: async () => {
await new Promise((resolve) => {
setTimeout(resolve, 500);
});
return 'testtoken';
} }
}, },
t: i18n.t, t: i18n.t,

View File

@ -21,7 +21,8 @@ export const FormPage: React.FC = () => {
setLoading(true); setLoading(true);
try { try {
await api.sendMagicLink({email, labels: options.labels}); const integrityToken = await api.getIntegrityToken();
await api.sendMagicLink({email, labels: options.labels, integrityToken});
if (minimal) { if (minimal) {
// Don't go to the success page, but show the success state in the form // Don't go to the success page, but show the success state in the form

View File

@ -12,14 +12,31 @@ export const setupGhostApi = ({siteUrl}: {siteUrl: string}) => {
} }
return { return {
sendMagicLink: async ({email, labels}: {email: string, labels: string[]}) => { getIntegrityToken: async (): Promise<string> => {
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 url = endpointFor({type: 'members', resource: 'send-magic-link'});
const payload = JSON.stringify({ const payload = JSON.stringify({
email, email,
emailType: 'signup', emailType: 'signup',
labels, labels,
urlHistory: getUrlHistory({siteUrl}) urlHistory: getUrlHistory({siteUrl}),
integrityToken
}); });
const response = await fetch(url, { const response = await fetch(url, {

View File

@ -65,5 +65,9 @@ export async function mockApi({page, status = 200}: {page: any, status?: number}
await route.abort('addressunreachable'); await route.abort('addressunreachable');
}); });
await page.route(`${MOCKED_SITE_URL}/members/api/integrity-token/`, async (route) => {
await route.fulfill('testtoken');
});
return lastApiRequest; return lastApiRequest;
} }