angular-sailsjs-boilerplate
angular-sailsjs-boilerplate copied to clipboard
Invalid user error message
Hi there,
First off - thanks for providing this splendid framework. One thing I noted in the backend: After installation and lifting, when attempt to login with credentials demo / demodemodemo I have got always "Invalid User" error message.
After few hours of debugging I found that in backend/api/services/protocols/local.js
- lines 91, 92:
protocol: 'local',
user: user.id
as a part of the db query to passport model. I switched to MongoDB and when I looked at passport.user field I saw '1' and '2', therefore the query above will never find user's passport. Would you be so kind and support me for fixing the bug?
Best Regards, Angel
I have the same issue, when I switch to MySQL. But in my case the bcrypt.compare() of the passwords fails. It finds the user and the passport, but then it fails.
Well,
After some additional research I found, that the issue is caused because of the way User & Password models are imported with barrels
module. What I did manually just to fix the bug is to edit user
field for each passport
record within the database. It allows me to login afterwards.
I believe the most right solution is explained here https://github.com/bredikhin/barrels#required-associations, but it means you have to fix the boilerplate code.
Best Regards, Angel
Hi, I fixed it manually for now. Thx for the tipp.
Regards, CLEMARC
Yeah, this is "known" problem with non-sql databases. Currently all of those fixtures relies that ID is integer. I have to look this closer soon.
That basically affects to Author / Book fixtures too.
I'm having this issue when I try to register a user. Any idea how to fix it?
@Tenkir I haven't implemented user registration yet see issue #22
I think I found a way to fix this issue.
Change backend/test/fixtures/User.json
to
[
{
"_id":1,
"username": "admin",
"email": "[email protected]",
"firstName": "Arnold",
"lastName": "Administrator",
"admin": true,
"createdUser": 1,
"updatedUser": 1
},
{
"_id":2,
"username": "demo",
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"admin": false,
"createdUser": 1,
"updatedUser": 1
}
]
In essence you just add the id manually so that mongoDb does not have to assign its own key.
Just for testing purposes.. You can assign any value as long as you remember to change the user
field inside backend/test/fixtures/Passport.json
. I'm too lazy to create a pull request just for that, but I think it will work for others as well.. Try it and let me know..
Hmm, did you try that also with sails-disk
and sails-mysql
adapters?
Nope, but I don't see why that woudln't work.. Except if _
is not allowed as a field character in MySQL etc..
I mean that in those id
is used as in primary key
not _id
, so I think this is going to broke those...
Good point, you're right! Well then perhaps 2 different fixture directories, would work. 1 for Mongo 1 for all the other dbs I guess.
var barrels;
if(someWayToFigureWeUseMongo)
barrels = new Barrels(./test/mongoFixtures/fixtures);
else
barrels = new Barrels(./test/defaultFixtures/fixtures);
Hmm. I'm not liking that idea of multiple fixtures for one object... I need to check this out more detailed level and try to figure out how to handle this.
But again, I can't promise anything :D - Too much to do and too little time to spare...
I was playing around with this the other day and I was about to submit a PR but realized it broke some other things, so I need to do some more research. I think the issue is actually with Barrels (or how we are using barrles) and how it handles associations.
I was trying to work around the issue by manually adding the an id
to the fixture, which fixed something things and broke others. Really, manually specifying id
s is a bad practice and we should avoid it. I think we need to setup the fixtures to load gradually with required associations as described here but I was having some trouble with that as well.
I am traveling at the moment but I was going to play with that some more soon later this week to see if I can fix it. If anyone else wants to give it a try as well, go for it.
Yeah, the problem lies really on usage of barrels, I think that there is proper way to use that with assoc so that will work on all databases. I'm open for those PR's
Switching to mongo broke the login functionality for me as well. Any updates on how to fix this ? At least a note saying that you'll have to manually update your users records would save us hours of debugging.
Yeah, that's true. I wish that I have some time to make this work with all those DB's. The main problem is with those fixtures and loading those with barrels, perhaps I need to look for another solution for fixture loading.
I've updated my passport object and set the user to the proper ObjectId("xyz"); this way I can log in again. I don't think it's a huge deal to be honest, just something to know before switching to another DB