Skip to content

Commit d973d14

Browse files
Fix: Button click not triggering action
The button click in the Shopify integration dialog was not triggering the expected action. This commit addresses the issue to ensure the button functions correctly.
1 parent 641dc37 commit d973d14

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/hooks/useShopifySupabase.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState, useCallback } from 'react';
22
import { supabase } from '@/integrations/supabase/client';
33
import { toast } from '@/hooks/use-toast';
4+
import { useAuth } from '@/contexts/AuthContext';
45

56
export interface ShopifyIntegration {
67
id: string;
@@ -25,17 +26,18 @@ export interface ShopifyIntegration {
2526
export const useShopifySupabase = (campaignId: string) => {
2627
const [integrations, setIntegrations] = useState<ShopifyIntegration[]>([]);
2728
const [isLoading, setIsLoading] = useState(false);
29+
const { user } = useAuth();
2830

2931
// Récupérer les intégrations existantes
3032
const fetchIntegrations = useCallback(async () => {
3133
try {
32-
const { data: { user } } = await supabase.auth.getUser();
3334
if (!user) throw new Error('Utilisateur non connecté');
3435

3536
const { data, error } = await supabase
3637
.from('shopify_integrations')
3738
.select('*')
3839
.eq('campaign_id', campaignId)
40+
.eq('user_id', user.uid)
3941
.eq('active', true)
4042
.order('created_at', { ascending: false });
4143

@@ -60,7 +62,7 @@ export const useShopifySupabase = (campaignId: string) => {
6062
variant: "destructive"
6163
});
6264
}
63-
}, [campaignId]);
65+
}, [campaignId, user]);
6466

6567
// Initier l'installation Shopify
6668
const initiateShopifyInstall = useCallback(async (shopName: string) => {
@@ -76,15 +78,14 @@ export const useShopifySupabase = (campaignId: string) => {
7678
setIsLoading(true);
7779

7880
try {
79-
const { data: { user } } = await supabase.auth.getUser();
8081
if (!user) throw new Error('Utilisateur non connecté');
8182

8283
// Appeler l'Edge Function pour générer l'URL d'autorisation
8384
const { data, error } = await supabase.functions.invoke('shopify-auth', {
8485
body: {
8586
shop: shopName.includes('.myshopify.com') ? shopName : `${shopName}.myshopify.com`,
8687
campaignId,
87-
userId: user.id
88+
userId: user.uid
8889
}
8990
});
9091

0 commit comments

Comments
 (0)