Skip to content

Commit b850cb4

Browse files
Fix redirect loop
The user is experiencing a redirect loop when trying to integrate Shopify. This commit aims to fix the issue by addressing the redirect behavior.
1 parent db818a8 commit b850cb4

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

src/components/ShopifyIntegrationDialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ export const ShopifyIntegrationDialog: React.FC<ShopifyIntegrationDialogProps> =
159159
open={showPrivateAppDialog}
160160
onOpenChange={setShowPrivateAppDialog}
161161
shopName={shopName}
162-
onConnect={handleConnect}
162+
onSuccess={() => {
163+
toast({
164+
title: "Configuration terminée !",
165+
description: "Votre boutique Shopify est maintenant connectée",
166+
});
167+
handleClose();
168+
}}
163169
/>
164170
</>
165171
);

src/components/ShopifyPrivateAppDialog.tsx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import { Label } from '@/components/ui/label';
66
import { Textarea } from '@/components/ui/textarea';
77
import { toast } from '@/hooks/use-toast';
88
import { ExternalLink, Copy, CheckCircle } from 'lucide-react';
9+
import { supabase } from '@/integrations/supabase/client';
910

1011
interface ShopifyPrivateAppDialogProps {
1112
open: boolean;
1213
onOpenChange: (open: boolean) => void;
1314
shopName: string;
14-
onConnect: (accessToken: string, shopDomain: string) => void;
15+
onSuccess: () => void; // Changé de onConnect vers onSuccess
1516
}
1617

1718
export const ShopifyPrivateAppDialog = ({
1819
open,
1920
onOpenChange,
2021
shopName,
21-
onConnect
22+
onSuccess
2223
}: ShopifyPrivateAppDialogProps) => {
2324
const [accessToken, setAccessToken] = useState('');
2425
const [loading, setLoading] = useState(false);
@@ -52,21 +53,44 @@ export const ShopifyPrivateAppDialog = ({
5253

5354
setLoading(true);
5455
try {
55-
// Pas de validation côté client à cause des problèmes CORS
56-
// La validation se fera côté serveur
56+
// Récupérer l'utilisateur connecté
57+
const { data: { user } } = await supabase.auth.getUser();
58+
if (!user) {
59+
toast({
60+
title: "Erreur",
61+
description: "Vous devez être connecté",
62+
variant: "destructive"
63+
});
64+
return;
65+
}
66+
67+
// Appeler l'edge function pour sauvegarder l'intégration
68+
const response = await supabase.functions.invoke('shopify-private-app', {
69+
body: {
70+
shopDomain,
71+
accessToken: accessToken.trim(),
72+
campaignId: 'test-campaign-123', // TODO: récupérer le vrai campaign ID
73+
userId: user.id
74+
}
75+
});
76+
77+
if (response.error) {
78+
throw new Error(response.error.message || 'Erreur lors de la connexion');
79+
}
80+
5781
toast({
58-
title: "Connexion en cours...",
59-
description: "Vérification du token avec votre boutique",
82+
title: "Shopify connecté !",
83+
description: `Boutique ${response.data.shopInfo.name} connectée avec succès`,
6084
});
6185

62-
onConnect(accessToken, shopDomain);
6386
onOpenChange(false);
87+
onSuccess();
6488

6589
} catch (error) {
66-
console.error('Erreur connexion:', error);
90+
console.error('Erreur connexion Shopify:', error);
6791
toast({
6892
title: "Erreur de connexion",
69-
description: "Une erreur s'est produite",
93+
description: error instanceof Error ? error.message : "Vérifiez votre token et réessayez",
7094
variant: "destructive"
7195
});
7296
} finally {

0 commit comments

Comments
 (0)