Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 error when using Mongo #85

Open
jes-carr opened this issue Jul 24, 2015 · 6 comments
Open

401 error when using Mongo #85

jes-carr opened this issue Jul 24, 2015 · 6 comments

Comments

@jes-carr
Copy link

You can reproduce it just by changing the connection from sails-disk to sails-mongo. When trying to log in you get a 401 (Unauthorized). It seems that the variable user is false, but not sure where is the issue.

@vcardins
Copy link

+1

@tarlepp
Copy link
Owner

tarlepp commented Aug 11, 2015

This is basically fixture problem, mongo doesn't use integer ID's like SQL based databases. So tl:dr when database is initialized created users don't have necessary passport relations attached.

@vcardins
Copy link

Sorry, I didn't exactly understand. Could you guide a workaround on this?

@tarlepp
Copy link
Owner

tarlepp commented Aug 11, 2015

See fixtures for User and Passport models, especially that Passport fixture, see that it relies to numeric id columns which are not supported by mongo.

So quick fix is to manually alter your mongo db data OR make a PR which fixes this, there is some solutions on barrels repo to make assocs work with fixtures, but basically I haven't had time to make this fix - yet.

@vcardins
Copy link

By updating it manually works, but of course is not ideal. I tried creating assocs fixtures but it seems that there is a bug with barrels: http://screencast.com/t/YQhoZ5bC. There is an open issue for that:
bredikhin/barrels#31.
I managed it to work by using another lib: pow-mongodb-fixtures. Not ideal cause I had to put all the data in a single file, maybe there is another way to load per file ... It solves the problem temporary, but I'd like to hear what would be the best solution to this.

load-db.js
...
var conn = sails.config.connections.someMongodbServer.database;
var fixtures = require('pow-mongodb-fixtures').connect(conn);

//File (loads content from data.js file)
var dir = '../../test/fixtures/js/';
fixtures.load(dir +'data.js', function(){
    next();
});
...

@tarlepp
Copy link
Owner

tarlepp commented Aug 13, 2015

Yeah, this one needs some serious work. Basically those fixtures should work as the same with any adapter, otherwise those aren't working like those should.

But basically this is only problem when creating new app when there isn't any data on db yet. And if your app is using mongo or something else you propably create fixtures using some specified tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants