diff --git a/client/src/App.tsx b/client/src/App.tsx index 8878f7b0..6ceda264 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -20,13 +20,13 @@ const App = () => { useEffect(() => { const socketStore = useSocketStore.getState(); - socketStore.init(); + socketStore.init(accessToken); return () => { setTimeout(() => { socketStore.cleanup(); }, 0); }; - }, []); + }, [accessToken]); return ( <> diff --git a/client/src/stores/useSocketStore.ts b/client/src/stores/useSocketStore.ts index ec5f8a03..0cb0b8ed 100644 --- a/client/src/stores/useSocketStore.ts +++ b/client/src/stores/useSocketStore.ts @@ -16,7 +16,7 @@ interface SocketStore { socket: Socket | null; clientId: number | null; workspace: WorkSpaceSerializedProps | null; - init: () => void; + init: (accessToken: string | null) => void; cleanup: () => void; fetchWorkspaceData: () => WorkSpaceSerializedProps | null; sendPageCreateOperation: (operation: RemotePageCreateOperation) => void; @@ -51,9 +51,8 @@ export const useSocketStore = create((set, get) => ({ clientId: null, workspace: null, - init: () => { + init: (accessToken: string | null) => { const { socket: existingSocket } = get(); - if (existingSocket?.connected) return; if (existingSocket) { existingSocket.disconnect(); @@ -68,6 +67,9 @@ export const useSocketStore = create((set, get) => ({ withCredentials: true, reconnectionAttempts: 5, reconnectionDelay: 1000, + auth: { + token: accessToken, + }, autoConnect: false, });