fix(backend+frontend): WebSocket auth, Yjs persistence fix, keep docs in memory (Issues #2, #4, #5)

This commit is contained in:
2026-06-29 23:33:58 +02:00
parent 2e9dfdfec0
commit cf62a777d2
6 changed files with 99 additions and 159 deletions
+4 -3
View File
@@ -16,6 +16,7 @@ export interface UseYjsBindingOptions {
userName: string;
userColor: string;
enabled?: boolean;
token?: string;
}
export interface UseYjsBindingResult {
@@ -44,7 +45,7 @@ export interface UseYjsBindingResult {
const DEFAULT_WS_URL = `wss://${window.location.host}`;
export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true } = opts;
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true, token } = opts;
const yjsDocRef = useRef<YjsDocument | null>(null);
const providerRef = useRef<WebSocketProvider | null>(null);
@@ -92,7 +93,7 @@ export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
const unbindLocal = provider.bindLocalUpdates();
// Connect
provider.connect();
provider.connect(token);
syncState();
// Cleanup
@@ -107,7 +108,7 @@ export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
providerRef.current = null;
awarenessRef.current = null;
};
}, [docName, wsUrl, userId, userName, userColor, enabled]);
}, [docName, wsUrl, userId, userName, userColor, enabled, token]);
// Mutators
const setElement = useCallback((el: CADElement) => {