Skip to content

Commit 7a46679

Browse files
authored
fix(shared): Check for valid resource prior to initializing a payment flow (#6436)
1 parent 22c35ef commit 7a46679

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.changeset/bumpy-melons-grow.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/shared': patch
3+
'@clerk/nextjs': patch
4+
'@clerk/clerk-react': patch
5+
---
6+
7+
Fixes a bug which cause initialization of a payment method to never fire.

packages/shared/src/react/commerce.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,21 @@ const usePaymentSourceUtils = (forResource: ForPayerType = 'user') => {
7474
key: 'commerce-payment-source-initialize',
7575
resourceId: resource?.id,
7676
},
77-
() =>
78-
resource?.initializePaymentSource({
77+
() => {
78+
return resource?.initializePaymentSource({
7979
gateway: 'stripe',
80-
}),
80+
});
81+
},
8182
);
83+
8284
const environment = useInternalEnvironment();
8385

8486
useEffect(() => {
87+
if (!resource?.id) return;
8588
initializePaymentSource().catch(() => {
8689
// ignore errors
8790
});
88-
}, []);
91+
}, [resource?.id]);
8992

9093
const externalGatewayId = initializedPaymentSource?.externalGatewayId;
9194
const externalClientSecret = initializedPaymentSource?.externalClientSecret;

0 commit comments

Comments
 (0)