mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 06:31:13 -05:00
Fix 406 errors and realtime auth
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useEnhancedRealtime, ConnectionState } from './useEnhancedRealtime';
|
||||
import { useUserRole } from './useUserRole';
|
||||
|
||||
interface UseRealtimeSubmissionsOptions {
|
||||
onInsert?: (payload: any) => void;
|
||||
@@ -10,6 +11,10 @@ interface UseRealtimeSubmissionsOptions {
|
||||
|
||||
export const useRealtimeSubmissions = (options: UseRealtimeSubmissionsOptions = {}) => {
|
||||
const { onInsert, onUpdate, onDelete, enabled = true } = options;
|
||||
const { isModerator, loading: roleLoading } = useUserRole();
|
||||
|
||||
// Only enable realtime when user is confirmed as moderator
|
||||
const realtimeEnabled = enabled && !roleLoading && isModerator();
|
||||
|
||||
// Use refs to store latest callbacks without triggering re-subscriptions
|
||||
const onInsertRef = useRef(onInsert);
|
||||
@@ -24,7 +29,7 @@ export const useRealtimeSubmissions = (options: UseRealtimeSubmissionsOptions =
|
||||
}, [onInsert, onUpdate, onDelete]);
|
||||
|
||||
const { channel, connectionState, reconnect } = useEnhancedRealtime({
|
||||
enabled,
|
||||
enabled: realtimeEnabled,
|
||||
channelName: 'content-submissions-changes',
|
||||
debug: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user