Login throws 401
I'm using version 2.14.0. I have a Model without properties using User as base.
When I do a POST to /api/Model/login
{"email": "[email protected]", "password": "password", "ttl": 1209600000}
I get
{
"error": {
"name": "Error",
"status": 401,
"message": "login failed",
"statusCode": 401,
"code": "LOGIN_FAILED",
"stack": "Error: login failed\n at /home/julian/Development/example/node_modules/loopback/common/models/user.js:204:26\n at /home/julian/Development/example/node_modules/loopback-datasource-juggler/lib/dao.js:1352:5\n at allCb (/home/julian/Development/example/node_modules/loopback-datasource-juggler/lib/dao.js:1291:7)\n at PostgreSQL.<anonymous> (/home/julian/Development/example/node_modules/loopback-connector-postgresql/lib/postgresql.js:741:7)\n at null.<anonymous> (/home/julian/Development/example/node_modules/loopback-connector-postgresql/lib/postgresql.js:133:7)\n at null.<anonymous> (/home/julian/Development/example/node_modules/loopback/node_modules/continuation-local-storage/context.js:74:17)\n at bound (domain.js:254:14)\n at runBound (domain.js:267:12)\n at Query.handleReadyForQuery (/home/julian/Development/example/node_modules/loopback-connector-postgresql/node_modules/pg/lib/query.js:80:10)\n at null.<anonymous> (/home/julian/Development/example/node_modules/loopback-connector-postgresql/node_modules/pg/lib/client.js:158:19)"
}
}
I've found the problem here https://github.com/strongloop/loopback/blob/master/common/models/user.js#L116-L145, the function only returns the username or email but never the password
the problem persist with the version 2.16.3
The problem has nothing to do with https://github.com/strongloop/loopback/blob/master/common/models/user.js#L116-L145. The query is only used to find matching users with username or email. Then the password is checked against the found record.
Please run your app with DEBUG=loopback:user node . to see what causes the login failure.
@raymondfeng Console returns
loopback:user The password is invalid for user [email protected] +36s
I have in the following boot-script
datasource.autoupdate('Model', function(err) {
if (err) {
console.log(err);
return;
}
app.models.Model.create([
{"email": "[email protected]", "password": "password"}
]);
});
@raymondfeng thanks for all your help, was doing several things wrong. and everything works as it should
@rkmax Do you remember what your issue was and how you resolved it? I'm getting the same error, and I'm wondering if I was doing the same wrong things.
@paulespinosa I don't recall in this moment. but try with the debug string that Raymond said, it gave me clues to solve the issue
Hai, I am getting the same error as you have posted @rkmax . I followed what @raymondfeng have told. But I am getting the following in the console.
loopback:user No matching record is found for user [email protected]
But I have created this user already. I dont no what I am missing. Can someone help? Thanks
@amazinggadget i have the same problem. My user exists in mongo db an i get the message no record found at login process... . Have you solve the problem?
@amazinggadget any news on this topic? I am facing the same problem :(
Same probleme here. :-/ Any suggestions to resolve it?
I'm having a similar problem. However I am able to make the first login, but then after I logout, on the second time I attempt to login I get the 401. Have no clue what's going on and it's been quite a frustrating journey.
same error... any suggestions?
same error
I am getting the same error... I can't find anything on this issue to fix it. I installed loopback globally, made a new project with the cli, ran it without changing any files, posted a new user object to POST api/Users, got a 200 response back, and when I try to login with the same email and password I get Error "401 Error: login failed EVERY TIME." What am I doing wrong?
I also tried with MongoDB & MySQL and there is no difference.
Same probleme...
I find that POST api/Users don't save password to db
I don't understand why, so I recreated project with 2.x version of LoopBack and everything works as it should.
I think that my problem in #4043 is related to that... As said in my issue registration emails me a token=undefined. Now if I try to login it returns a LOGIN_FAILED. I've checked and the User is created in the DB
I confirm, as @ramirus said, that password is not saved into DB. Also verificationToken is not present. If I run from my pc everything works well, verificationToken and password are correctly created and inserted into DB. What's is going on? It worked a week ago :/
UPDATE I've found the reason why is working on local and not on the server. I think that is a problem with some packages from packages.json. It was using the dependencies from yarn.lock file. Now I've set dependencies in packages.json without ^ and using the same version as .lock file and now is working. This is my packages.json file:
"dependencies": {
"compression": "^1.7.3",
"cors": "^2.8.4",
"helmet": "^3.13.0",
"loopback": "3.22.2",
"loopback-boot": "2.27.1",
"loopback-cascade-delete-mixin": "2.0.0",
"loopback-component-explorer": "6.2.0",
"loopback-component-storage": "3.5.0",
"loopback-connector-mongodb": "3.6.0",
"loopback-ds-timestamp-mixin": "3.4.1",
"loopback-connector-remote":"3.4.0",
"loopback-connector":"4.5.1",
"loopback-datasource-juggler":"3.23.0",
"loopback-phase":"3.3.0",
"loopback-swagger":"5.7.0",
"loopback3-xtotalcount": "^0.1.2",
"redis": "^2.8.0",
"serve-favicon": "^2.0.1",
"strong-error-handler": "^3.2.0"
},
These is something wrong with one of these dependencies. However try to modify the file and write back if is working.