I have created a new sails project and installed sails-permission. First it worked fine. After creating connection to Mysql and did sails lift it throws an error as
error: Error: Consistency violation: A model (`passport`) references a
datastore which cannot be found ('mysql'). If this model definition
has an explicit
connection
property, check that it is spelled
correctly. If not, check your default
connection
(usually located in config/models.js).
The Model passport.js is located in node_modules/sails-permission/api/models
.
config/connections.js
mysql: {
module : 'sails-mysql',
host : '127.0.0.1',
port : 3306,
user : 'review',
password : 'review',
database : 'reviews'
},
config/models.js
module.exports.models = {
connection: 'mysql',
migrate: 'alter'
};
node_modules/sails-permission/api/models
var bcrypt = require('bcryptjs');
function hashPassword (passport, next) {
var config = sails.config.auth.bcrypt;
var salt = config.salt || config.rounds;
if (passport.password) {
bcrypt.hash(passport.password, salt, function (err, hash) {
if (err) {
delete passport.password;
sails.log.error(err);
throw err;
}
passport.password = hash;
next(null, passport);
});
}
else {
next(null, passport);
}
}
var Passport = {
attributes: {
password: { type: 'string', minLength: 8 },
provider : { type: 'alphanumericdashed' },
identifier : { type: 'string' },
tokens : { type: 'json' },
user: { model: 'User', required: true },
validatePassword: function (password, next) {
bcrypt.compare(password, this.password, next);
}
},
beforeCreate: function (passport, next) {
hashPassword(passport, next);
},
beforeUpdate: function (passport, next) {
hashPassword(passport, next);
}
};
module.exports = Passport;
It beacause of sails-mysql update. [https://github.com/balderdashy/sails-mysql/pull/328/files].
Change
module
asadapter
in