Skip to content

Commit af719ed

Browse files
committed
fix: missing csrf token for stripe
Stripe integration uses `v1 api`, where `csrf token` is needed. We are not using `csrfStore` since this will be removed soon. See: https://github.com/gobitfly/eth2-beaconchain-explorer/blob/2f960a87aaa8443e6a537203b7ba78f27530286c/templates/payment/pricing.html#L38 See: https://bitfly1.atlassian.net/browse/BEDS-1539
1 parent ba7dbca commit af719ed

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

frontend/composables/useStripeProvider.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ export function useStripeProvider() {
2525
)
2626
})
2727

28+
const { apiClient } = useRuntimeConfig().public
29+
const csrfToken = ref()
2830
const stripeInit = async (stripePulicKey: string) => {
2931
if (stripePulicKey === '') {
3032
return
3133
}
32-
34+
await $fetch(`${apiClient}/pricing`, {
35+
onResponse({
36+
response,
37+
}) {
38+
csrfToken.value = response.headers.get('x-csrf-token') ?? ''
39+
},
40+
})
3341
stripe.value = await loadStripe(stripePulicKey)
3442
}
3543

@@ -45,6 +53,9 @@ export function useStripeProvider() {
4553
{
4654
baseURL: stripeBaseUrl,
4755
body: JSON.stringify({ returnURL: window.location.href }),
56+
headers: {
57+
'x-csrf-token': csrfToken.value,
58+
},
4859
},
4960
)
5061

@@ -69,6 +80,9 @@ export function useStripeProvider() {
6980
priceId,
7081
promotionCode: promoCode,
7182
}),
83+
headers: {
84+
'x-csrf-token': csrfToken.value,
85+
},
7286
},
7387
)
7488

0 commit comments

Comments
 (0)