From 67b47fd868fbb9f323d0e9a52072c5630385ec43 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Sat, 22 Jul 2017 01:15:13 +0200 Subject: [PATCH] bugfix - sync step 2 also authenticates) --- src/Connector.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Connector.js b/src/Connector.js index b062f528..03be952e 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -269,17 +269,20 @@ export default function extendConnector (Y/* :any */) { }) return Promise.reject(new Error('Incompatible protocol version')) } - if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == null) { + if ((message.type === 'sync step 1' || message.type === 'sync step 2') && this.connections[sender] != null && this.connections[sender].auth == null) { // authenticate using auth in message var auth = this.checkAuth(message.auth, this.y) this.connections[sender].auth = auth auth.then(auth => { // in case operations were received before sender was received // we apply the messages after authentication - this.connections[sender].waitingMessages.forEach(msg => { - this.receiveMessage(sender, msg) + this.connections[sender].syncStep2.promise.then(() => { + // we do it after sync step 1 + this.connections[sender].waitingMessages.forEach(msg => { + this.receiveMessage(sender, msg) + }) + this.connections[sender].waitingMessages = null }) - this.connections[sender].waitingMessages = null for (var f of this.userEventListeners) { f({ action: 'userAuthenticated', @@ -389,7 +392,7 @@ export default function extendConnector (Y/* :any */) { }) } else if (this.connections[sender] != null) { // wait for authentication - let senderConn = this.connection[sender] + let senderConn = this.connections[sender] senderConn.waitingMessages = senderConn.waitingMessages || [] senderConn.waitingMessages.push(message) } else {