Skip to content

Commit 5aecc68

Browse files
Fix Shopify OAuth redirect URI mismatch
The `redirect_uri` and application URL must have matching hosts for Shopify OAuth to work correctly. This commit ensures that the `redirect_uri` used in the authorization request matches the application's host.
1 parent 792fc21 commit 5aecc68

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/pages/ShopifyCallbackPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ export const ShopifyCallbackPage: React.FC = () => {
3636

3737
const { campaignId } = JSON.parse(storedData);
3838

39-
// Finaliser l'installation
40-
const response = await fetch('/api/shopify-auth-callback', {
39+
// Finaliser l'installation avec Supabase
40+
const response = await fetch('https://wsvhmozduyiftmuuynpi.supabase.co/functions/v1/shopify-callback', {
4141
method: 'POST',
4242
headers: {
4343
'Content-Type': 'application/json',
44+
'Authorization': `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indzdmhtb3pkdXlpZnRtdXV5bnBpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTU4NDQ3OTEsImV4cCI6MjA3MTQyMDc5MX0.eLzX-f5tIJvbqBLB1lbSM0ex1Rz1p6Izemi0NnqiWz4`
4445
},
4546
body: JSON.stringify({
4647
shop,
4748
code,
48-
state,
49-
campaignId
49+
state
5050
})
5151
});
5252

supabase/functions/shopify-auth/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ serve(async (req) => {
6060
'write_themes'
6161
].join(',');
6262

63-
const redirectUri = `${req.headers.get('origin')}/shopify/callback`;
63+
// Utiliser une URL de redirection fixe pour éviter les problèmes avec les URLs dynamiques
64+
const origin = req.headers.get('origin') || '';
65+
const isProduction = origin.includes('refspring.com');
66+
const redirectUri = isProduction
67+
? 'https://refspring.com/shopify/callback'
68+
: `${origin}/shopify/callback`;
6469

6570
const authUrl = new URL(`https://${shopDomain}/admin/oauth/authorize`);
6671
authUrl.searchParams.set('client_id', shopifyApiKey);

0 commit comments

Comments
 (0)