0

I have inherited a half-complete project (app) developed in Angular/Sails/PostgreSQL

I have no previous experience of Angular, Sails.js, or PostgreSQL

The app works on live, and is currently running, and several important users are using it.

This app didn't run at all on staging until I did 'mkdir logs', and then had the 'ReferenceError: Promise is not defined', so I think that the app might have been developed on live/configured on live.

I have set up a local development environment and am seeing this 'ReferenceError' error too.

I suspect that a configuration issue is the cause of this issue, however I have no idea what I've missed if that is the case.

I have tried various commands such as 'npm install', 'npm update', and downgrading various packages, and currently the code, package.json etc. is an exact copy of live, and the modules should be the exact same versions.

I can create a new sails project, and everything works ok when viewing in the browser.

Shell Output of sails lift:

vagrant@sails-vagrant-machine:~/dev/project$ sails lift

info: Starting app...

  i18n:debug will write to /home/vagrant/dev/project/config/locales/en.json +0ms
  i18n:debug read /home/vagrant/dev/project/config/locales/en.json for locale: en +0ms
  i18n:debug will write to /home/vagrant/dev/project/config/locales/es.json +1ms
  i18n:debug read /home/vagrant/dev/project/config/locales/es.json for locale: es +1ms
  i18n:debug will write to /home/vagrant/dev/project/config/locales/fr.json +0ms
  i18n:debug read /home/vagrant/dev/project/config/locales/fr.json for locale: fr +1ms
  i18n:debug will write to /home/vagrant/dev/project/config/locales/de.json +0ms
  i18n:debug read /home/vagrant/dev/project/config/locales/de.json for locale: de +0ms
[ReferenceError: Promise is not defined]
undefined
Unhandled rejection TypeError: Cannot read property 'message' of undefined
    at /home/vagrant/dev/project/api/controllers/AuthController.js:23:34
    at Strategy.strategy.error (/home/vagrant/dev/project/node_modules/passport/lib/middleware/authenticate.js:333:18)
    at verified (/home/vagrant/dev/project/node_modules/passport-local/lib/strategy.js:81:28)
    at /home/vagrant/dev/project/config/passport.js:79:20
    at tryCatcher (/home/vagrant/dev/project/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:507:31)
    at Promise._settlePromiseAt (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:581:18)
    at Promise._settlePromises (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:697:14)
    at Async._drainQueue (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:133:10)
    at Async.drainQueues (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:15:14)
    at process._tickDomainCallback (node.js:463:13)

package.json:

{
  "name": "project",
  "private": true,
  "version": "0.0.0",
  "description": "a Sails application",
  "keywords": [],
  "dependencies": {
    "ap": "^0.2.0",
    "async": "^1.4.2",
    "bcrypt": "~0.8.0",
    "bluebird": "^2.10.0",
    "crypto": "0.0.3",
    "ejs": "~0.8.4",
    "email-templates": "^2.0.1",
    "forever": "^0.15.1",
    "grunt": "0.4.2",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-coffee": "~0.10.1",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-copy": "~0.5.0",
    "grunt-contrib-cssmin": "~0.9.0",
    "grunt-contrib-jst": "~0.6.0",
    "grunt-contrib-less": "0.11.1",
    "grunt-contrib-uglify": "~0.4.0",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-sails-linker": "~0.9.5",
    "grunt-sync": "~0.0.4",
    "html-pdf": "^1.4.0",
    "include-all": "~0.1.3",
    "less": "^2.5.1",
    "mandrill-api": "^1.0.45",
    "moment": "^2.10.6",
    "passport": "~0.2.1",
    "passport-local": "~1.0.0",
    "postgres-array": "^1.0.0",
    "postgres-bytea": "^1.0.0",
    "postgres-date": "^1.0.0",
    "rc": "~0.5.0",
    "request": "^2.62.0",
    "sails": "~0.11.0",
    "sails-disk": "~0.10.0",
    "sails-postgresql": "^0.10.16",
    "sp": "^0.1.3",
    "waterline": "^0.10.26",
    "winston": "^1.0.1"
  },
  "scripts": {
    "start": "node app.js",
    "debug": "node debug app.js"
  },
  "main": "app.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/**.....**/project.git"
  },
  "author": "**.....**",
  "license": ""
}

api/controllers/AuthController.js:

/**
 * AuthController
 *
 * @description :: Server-side logic for managing auths
 * @help        :: See http://links.sailsjs.org/docs/controllers
 */

var passport = require('passport');
var bcrypt = require('bcrypt');

module.exports = {
    _config: {
        actions: false,
        shortcuts: false,
        rest: false
    },
    login: function(req, res) {
        passport.authenticate('local', function(err, user, info) {
            console.log(err);
            console.log(user);
            if ((err) || (!user)) {
                return res.send({
                    message: info.message,
                    user: user
                });
            } else {
                req.logIn(user, function (err) {
                    if (err) res.send(err);
                    return res.send({
                        message: info.message,
                        user: user
                    });
                });
            }
        })(req, res);
    },
    logout: function(req, res) {
        req.logout();
        res.redirect('/');
    }
};

I would really appreciate some help on this.

Joe Hill
  • 333
  • 3
  • 12

1 Answers1

1

info is not an object on your passport.authenticate line.

passport.authenticate('local', function(err, user, info) {

You logged err and user but you did not log info - had you logged info, you would've seen undefined so you can not use it's message property on this line:

return res.send({
  message: info.message,
  user: user
});
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100