OptimalBits / node_acl

Access control lists for node applications
2.62k stars 369 forks source link

How to use acl with mongoose #199

Open ghost opened 8 years ago

ghost commented 8 years ago

Hey,

// I create a pastebin of the code: http://pastebin.com/2MVuMmM8 // I dont know why its not format here... with Mongo i do this:

mongoose.connect("mongodb://localhost:27017/xeorMain", function(err) { if (err) { console.log("ERROR");

}
acl = new acl(new acl.mongodbBackend(mongoose.connection, 'acl_'));
acl.allow('guest', 'blogs', 'view');
acl.allow('admin', 'blogs', 'edit');

});

and in mongoose i try this:

mongoose.connect("mongodb://localhost:27017/xeorMain", function(err) { if (err) { console.log("ERROR");

}
acl = new acl(new acl.mongodbBackend(mongoose.connection, 'acl_'));
acl.allow('guest', 'blogs', 'view');
acl.allow('admin', 'blogs', 'edit');

});

but this doesn't work. Is the acl param wrong with "mongoose.connection"?

Greetz

designeng commented 8 years ago

Do not use mongoose.connection as db instance - it has a type NativeConnection (realized interface MongooseConnection). The right way:

javascript var acl = new ACL.mongodbBackend(mongoose.connection.db);