Explorar o código

Added some undefined checks in userList function.

KrisVos130 %!s(int64=9) %!d(string=hai) anos
pai
achega
06704ecd6a
Modificáronse 1 ficheiros con 3 adicións e 3 borrados
  1. 3 3
      app/server/server.js

+ 3 - 3
app/server/server.js

@@ -161,8 +161,9 @@ function Station(type) {
         Playlists.update({type: type}, {$push: {songs: default_song.mid}});
     }
     Meteor.publish(type, function () {
-        var username = Meteor.users.findOne(this.userId).profile.username;
-        if (username !== undefined) {
+        var user = Meteor.users.findOne(this.userId);
+        if (this.userId !== undefined && user !== undefined && user.profile !== undefined && user.profile.username !== undefined) {
+            var username = user.profile.username;
             Rooms.update({type: type}, {$push: {userList: username}});
             this.onStop(function() {
                 var list = Rooms.findOne({type: type}).userList;
@@ -170,7 +171,6 @@ function Station(type) {
                 if (index >= 0) {
                     list.splice( index, 1 );
                 }
-
                 Rooms.update({type: type}, {$set: {userList: list}});
             });
         }