Need to check for undefined.

master
Håvar Aambø Fosstveit 2019-10-25 13:52:13 +02:00
parent 39c3f7c36d
commit 6dc3f537e4
1 changed files with 10 additions and 7 deletions

View File

@ -36,6 +36,8 @@ class Peer extends EventEmitter
this._consumers = new Map();
this._checkAuthentication();
this._handlePeer();
}
@ -60,15 +62,9 @@ class Peer extends EventEmitter
_handlePeer()
{
this.authenticated =
this.socket.handshake.session.passport &&
this.socket.handshake.session.passport.user;
this.socket.use((packet, next) =>
{
this.authenticated =
this.socket.handshake.session.passport &&
this.socket.handshake.session.passport.user;
this._checkAuthentication();
return next();
});
@ -84,6 +80,13 @@ class Peer extends EventEmitter
});
}
_checkAuthentication()
{
this.authenticated =
Boolean(this.socket.handshake.session.passport) &&
Boolean(this.socket.handshake.session.passport.user);
}
get id()
{
return this._id;