Corrige le Realtime qui ne diffusait aucun événement à travers l'app
Build and deploy / deploy (push) Successful in 37s
Build and deploy / deploy (push) Successful in 37s
Les canaux Realtime (Char, Gardien, classement, journal, calendrier, Icare) s'abonnaient juste après createClient(), avant que la session ne soit chargée de façon asynchrone — le canal rejoignait donc Supabase en rôle "anon" au lieu de "authenticated", et les policies RLS "to authenticated" bloquaient silencieusement tous les événements (l'abonnement lui-même réussissait, ce qui masquait le problème). Ajoute waitForRealtimeAuth() dans src/lib/supabase/client.ts, qui attend la session et pousse explicitement le token avant de s'abonner. Vérifié avec deux sessions navigateur distinctes : les changements se propagent maintenant réellement sans rechargement.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { createClient } from "@/lib/supabase/client";
|
||||
import { createClient, waitForRealtimeAuth } from "@/lib/supabase/client";
|
||||
|
||||
type Entry = {
|
||||
id: number;
|
||||
@@ -31,20 +31,27 @@ export function JournalView({
|
||||
|
||||
useEffect(() => {
|
||||
const supabase = createClient();
|
||||
const channel = supabase
|
||||
.channel("journal-points-log")
|
||||
.on(
|
||||
"postgres_changes",
|
||||
{ event: "INSERT", schema: "public", table: "points_log" },
|
||||
(payload) => {
|
||||
const row = payload.new as Entry;
|
||||
setEntries((current) => [row, ...current]);
|
||||
},
|
||||
)
|
||||
.subscribe();
|
||||
let channel: ReturnType<typeof supabase.channel> | null = null;
|
||||
let cancelled = false;
|
||||
|
||||
waitForRealtimeAuth(supabase).then(() => {
|
||||
if (cancelled) return;
|
||||
channel = supabase
|
||||
.channel("journal-points-log")
|
||||
.on(
|
||||
"postgres_changes",
|
||||
{ event: "INSERT", schema: "public", table: "points_log" },
|
||||
(payload) => {
|
||||
const row = payload.new as Entry;
|
||||
setEntries((current) => [row, ...current]);
|
||||
},
|
||||
)
|
||||
.subscribe();
|
||||
});
|
||||
|
||||
return () => {
|
||||
supabase.removeChannel(channel);
|
||||
cancelled = true;
|
||||
if (channel) supabase.removeChannel(channel);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user