var ipcRenderer = require('electron').ipcRenderer;
var remote = require('electron').remote;

function setupUserListener() {
  document.addEventListener("DOMContentLoaded", function (event) {
    remote.getCurrentWindow().webContents.executeJavaScript(
      'new Promise((resolve, reject) => { if (SESSION) { SESSION.once("init", function () { resolve({ id: this.id, name: this.get("name"), email: this.get("email") }); }); SESSION.once("noAuth", function () { resolve(null); }); } else { resolve(null); } });'
    ).then((result) => {
      ipcRenderer.send('set-user', result);
    });
  });
}

module.exports = setupUserListener;

@@ -301,16 +301,128 @@
 SSION) %7B
+ if (SESSION.id) %7B resolve(%7B id: SESSION.id, name: SESSION.get(%22name%22), email: SESSION.get(%22email%22) %7D); %7D else %7B
  SESSION
@@ -463,20 +463,23 @@
 e(%7B id: 
-this
+SESSION
 .id, nam
@@ -481,20 +481,23 @@
 , name: 
-this
+SESSION
 .get(%22na
@@ -513,12 +513,15 @@
 il: 
-this
+SESSION
 .get
@@ -537,16 +537,18 @@
  %7D); %7D);
+ %7D
  SESSION

Check if we already have a user when calling set-user