title: node.js-Cannot read property 'email' of undefined
body: <p>When I run the code, it shows "User was registered successfully", but followed with "Cannot read property 'email' of undefined". 
  I try to fix the error, but failed. I think it may be some error in userRecord, but I checked many times and can't find what's the problem.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>var app = require('express')();
  
  var http = require('http').Server(app);
  
  var io = require('socket.io')(http);
  
  var admin = require("firebase-admin");
  
  var userAccountRequests = (io) =&gt;{
    io.on('connection',(socket)=&gt;{
      console.log(`Client ${socket.id} is connected`);
  
      detectDisconnection(socket,io);
      registerUser(socket,io);
  
    });
  };
  </code></pre>
  
  <p>I think there may be some error here. It can show the "successfully" message, but I think I have defined email.</p>
  
  <pre><code>function registerUser(socket,io){
    socket.on('userData',(data)=&gt;{
      admin.auth().createUser({
        email:data.email,
        displayname:data.userName,
        password:data.password
      })
      .then((userRecord)=&gt;{
        console.log('User was registered successfully');
        var db = admin.database();
        var ref = db.ref('users');
        var userRef = ref.child(encodeEmail(data.email));
        var data = {
          data:admin.database.ServerValue.TIMESTAMP
        };
        userRef.ser({
          email:data.email,
          userName:data.userName,
          dataJoined:date,
          hasLoggedIn:false
        });
  
        //send message to Client
        Object.keys(io.sockets.sockets).forEach((id)=&gt;{
          if(id == socket.id){
            var message = {
              text:'Success'
            }
            io.to(id).emit('message',{message});
          }
        });
      }).catch((error)=&gt;{
        Object.keys(io.sockets.sockets).forEach((id)=&gt;{
          console.log(error.message);
          if(id == socket.id){
            var message = {
              text:error.message
            }
            io.to(id).emit('message',{message});
          }
        });
  
      });
  
    });
  }
  
  function detectDisconnection(socket,io){
    socket.on('disconnect',()=&gt;{
      console.log('Client has disconnected');
    });
  }
  
  function encodeEmail(email) {
    return email.replace('.',',');
  
  }
  
  module.exports = {
    userAccountRequests
  }
  </code></pre>