bugfix - sync step 2 also authenticates)

This commit is contained in:
Kevin Jahns 2017-07-22 01:15:13 +02:00
parent 2c18b9ffad
commit 67b47fd868

View File

@ -269,17 +269,20 @@ export default function extendConnector (Y/* :any */) {
}) })
return Promise.reject(new Error('Incompatible protocol version')) 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 // authenticate using auth in message
var auth = this.checkAuth(message.auth, this.y) var auth = this.checkAuth(message.auth, this.y)
this.connections[sender].auth = auth this.connections[sender].auth = auth
auth.then(auth => { auth.then(auth => {
// in case operations were received before sender was received // in case operations were received before sender was received
// we apply the messages after authentication // we apply the messages after authentication
this.connections[sender].waitingMessages.forEach(msg => { this.connections[sender].syncStep2.promise.then(() => {
this.receiveMessage(sender, msg) // 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) { for (var f of this.userEventListeners) {
f({ f({
action: 'userAuthenticated', action: 'userAuthenticated',
@ -389,7 +392,7 @@ export default function extendConnector (Y/* :any */) {
}) })
} else if (this.connections[sender] != null) { } else if (this.connections[sender] != null) {
// wait for authentication // wait for authentication
let senderConn = this.connection[sender] let senderConn = this.connections[sender]
senderConn.waitingMessages = senderConn.waitingMessages || [] senderConn.waitingMessages = senderConn.waitingMessages || []
senderConn.waitingMessages.push(message) senderConn.waitingMessages.push(message)
} else { } else {