Sails JS helpers error resolving/ rejecting
up vote
0
down vote
favorite
I am using Helpers in Sails for login.
This is my helpers/login.js:
fn: async function (inputs, exits)
const password = inputs.password;
const email = inputs.email;
// find user with email
const user = await User.findOne(email);
if (user)
const salt = user.salt;
const hashedPass = user.password;
const iterations = user.iterations;
// check if input password matches with password in DB
crypto.pbkdf2(password, salt, iterations, 64, 'sha512',
(err, key) =>
if (!err)
if (hashedPass === key.toString('hex'))
// password matched
return exits.success(code: 200);
);
// account not found or password doesnt match
return exits.success(code: 404);
UserController.js:
login: async function(req, res)
let loginUser;
try
loginUser = await sails.helpers.login.with(
email: req.body.email, password: req.body.password
);
catch (e)
console.log("Error login in usercontroller ", e.message);
return res.serverError();
if (loginUser.code == 200)
return res.ok();
else
return res.serverError();
The problem lies in the Helper when I have the right email and password it's meant to return a code: 200 although it returns code: 404. With error message from node:
WARNING: Something seems to be wrong with this function.
It is trying to signal that it has finished AGAIN, after
already resolving/rejecting once.
(silently ignoring this...)
, same when I input wrong username/ email it returns that message. But when I remove return exits.success(code: 404) and input right email and password, it returns the right code (200). I need help fixing it.
node.js sails.js
add a comment |
up vote
0
down vote
favorite
I am using Helpers in Sails for login.
This is my helpers/login.js:
fn: async function (inputs, exits)
const password = inputs.password;
const email = inputs.email;
// find user with email
const user = await User.findOne(email);
if (user)
const salt = user.salt;
const hashedPass = user.password;
const iterations = user.iterations;
// check if input password matches with password in DB
crypto.pbkdf2(password, salt, iterations, 64, 'sha512',
(err, key) =>
if (!err)
if (hashedPass === key.toString('hex'))
// password matched
return exits.success(code: 200);
);
// account not found or password doesnt match
return exits.success(code: 404);
UserController.js:
login: async function(req, res)
let loginUser;
try
loginUser = await sails.helpers.login.with(
email: req.body.email, password: req.body.password
);
catch (e)
console.log("Error login in usercontroller ", e.message);
return res.serverError();
if (loginUser.code == 200)
return res.ok();
else
return res.serverError();
The problem lies in the Helper when I have the right email and password it's meant to return a code: 200 although it returns code: 404. With error message from node:
WARNING: Something seems to be wrong with this function.
It is trying to signal that it has finished AGAIN, after
already resolving/rejecting once.
(silently ignoring this...)
, same when I input wrong username/ email it returns that message. But when I remove return exits.success(code: 404) and input right email and password, it returns the right code (200). I need help fixing it.
node.js sails.js
I suspect the problem is because of the pbkdf2 callback function. It returnsreturn exits.success(code: 404);andreturn exits.success(code: 200);I still have to learn the async environment so please if anyone have any reference it will be great! My solution now is to use bcrypt module as it supports async/ await.
– adis
Nov 9 at 7:15
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using Helpers in Sails for login.
This is my helpers/login.js:
fn: async function (inputs, exits)
const password = inputs.password;
const email = inputs.email;
// find user with email
const user = await User.findOne(email);
if (user)
const salt = user.salt;
const hashedPass = user.password;
const iterations = user.iterations;
// check if input password matches with password in DB
crypto.pbkdf2(password, salt, iterations, 64, 'sha512',
(err, key) =>
if (!err)
if (hashedPass === key.toString('hex'))
// password matched
return exits.success(code: 200);
);
// account not found or password doesnt match
return exits.success(code: 404);
UserController.js:
login: async function(req, res)
let loginUser;
try
loginUser = await sails.helpers.login.with(
email: req.body.email, password: req.body.password
);
catch (e)
console.log("Error login in usercontroller ", e.message);
return res.serverError();
if (loginUser.code == 200)
return res.ok();
else
return res.serverError();
The problem lies in the Helper when I have the right email and password it's meant to return a code: 200 although it returns code: 404. With error message from node:
WARNING: Something seems to be wrong with this function.
It is trying to signal that it has finished AGAIN, after
already resolving/rejecting once.
(silently ignoring this...)
, same when I input wrong username/ email it returns that message. But when I remove return exits.success(code: 404) and input right email and password, it returns the right code (200). I need help fixing it.
node.js sails.js
I am using Helpers in Sails for login.
This is my helpers/login.js:
fn: async function (inputs, exits)
const password = inputs.password;
const email = inputs.email;
// find user with email
const user = await User.findOne(email);
if (user)
const salt = user.salt;
const hashedPass = user.password;
const iterations = user.iterations;
// check if input password matches with password in DB
crypto.pbkdf2(password, salt, iterations, 64, 'sha512',
(err, key) =>
if (!err)
if (hashedPass === key.toString('hex'))
// password matched
return exits.success(code: 200);
);
// account not found or password doesnt match
return exits.success(code: 404);
UserController.js:
login: async function(req, res)
let loginUser;
try
loginUser = await sails.helpers.login.with(
email: req.body.email, password: req.body.password
);
catch (e)
console.log("Error login in usercontroller ", e.message);
return res.serverError();
if (loginUser.code == 200)
return res.ok();
else
return res.serverError();
The problem lies in the Helper when I have the right email and password it's meant to return a code: 200 although it returns code: 404. With error message from node:
WARNING: Something seems to be wrong with this function.
It is trying to signal that it has finished AGAIN, after
already resolving/rejecting once.
(silently ignoring this...)
, same when I input wrong username/ email it returns that message. But when I remove return exits.success(code: 404) and input right email and password, it returns the right code (200). I need help fixing it.
node.js sails.js
node.js sails.js
asked Nov 8 at 14:18
adis
11019
11019
I suspect the problem is because of the pbkdf2 callback function. It returnsreturn exits.success(code: 404);andreturn exits.success(code: 200);I still have to learn the async environment so please if anyone have any reference it will be great! My solution now is to use bcrypt module as it supports async/ await.
– adis
Nov 9 at 7:15
add a comment |
I suspect the problem is because of the pbkdf2 callback function. It returnsreturn exits.success(code: 404);andreturn exits.success(code: 200);I still have to learn the async environment so please if anyone have any reference it will be great! My solution now is to use bcrypt module as it supports async/ await.
– adis
Nov 9 at 7:15
I suspect the problem is because of the pbkdf2 callback function. It returns
return exits.success(code: 404); and return exits.success(code: 200); I still have to learn the async environment so please if anyone have any reference it will be great! My solution now is to use bcrypt module as it supports async/ await.– adis
Nov 9 at 7:15
I suspect the problem is because of the pbkdf2 callback function. It returns
return exits.success(code: 404); and return exits.success(code: 200); I still have to learn the async environment so please if anyone have any reference it will be great! My solution now is to use bcrypt module as it supports async/ await.– adis
Nov 9 at 7:15
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The problem may be that you are trying to return an error code as a 'success' exit. In your exits object, you should make one like notFound: responseType: 'notFound' , then when you want to use it in your code, you do return exits.notFound(). Here is an example: https://sailsjs.com/documentation/concepts/actions-and-controllers#?actions-2
Read the question again. I have an error message ofWARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)
– adis
Nov 9 at 3:31
1
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Yes, good one @streleck!
– adis
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The problem may be that you are trying to return an error code as a 'success' exit. In your exits object, you should make one like notFound: responseType: 'notFound' , then when you want to use it in your code, you do return exits.notFound(). Here is an example: https://sailsjs.com/documentation/concepts/actions-and-controllers#?actions-2
Read the question again. I have an error message ofWARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)
– adis
Nov 9 at 3:31
1
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Yes, good one @streleck!
– adis
yesterday
add a comment |
up vote
0
down vote
The problem may be that you are trying to return an error code as a 'success' exit. In your exits object, you should make one like notFound: responseType: 'notFound' , then when you want to use it in your code, you do return exits.notFound(). Here is an example: https://sailsjs.com/documentation/concepts/actions-and-controllers#?actions-2
Read the question again. I have an error message ofWARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)
– adis
Nov 9 at 3:31
1
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Yes, good one @streleck!
– adis
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
The problem may be that you are trying to return an error code as a 'success' exit. In your exits object, you should make one like notFound: responseType: 'notFound' , then when you want to use it in your code, you do return exits.notFound(). Here is an example: https://sailsjs.com/documentation/concepts/actions-and-controllers#?actions-2
The problem may be that you are trying to return an error code as a 'success' exit. In your exits object, you should make one like notFound: responseType: 'notFound' , then when you want to use it in your code, you do return exits.notFound(). Here is an example: https://sailsjs.com/documentation/concepts/actions-and-controllers#?actions-2
answered Nov 8 at 18:20
streleck
26019
26019
Read the question again. I have an error message ofWARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)
– adis
Nov 9 at 3:31
1
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Yes, good one @streleck!
– adis
yesterday
add a comment |
Read the question again. I have an error message ofWARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)
– adis
Nov 9 at 3:31
1
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Yes, good one @streleck!
– adis
yesterday
Read the question again. I have an error message of
WARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)– adis
Nov 9 at 3:31
Read the question again. I have an error message of
WARNING: Something seems to be wrong with this function. It is trying to signal that it has finished AGAIN, after already resolving/rejecting once. (silently ignoring this...)– adis
Nov 9 at 3:31
1
1
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Ok now I have a little better of an idea. What is happening is that your 404 exit is getting triggered no matter what, because the 200 exit is within a callback that is not getting executed until after the 404. That means on a successful login, the exit is getting called twice. The simplest solution is to use await instead of a callback.
– streleck
Nov 9 at 15:59
Yes, good one @streleck!
– adis
yesterday
Yes, good one @streleck!
– adis
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209622%2fsails-js-helpers-error-resolving-rejecting%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I suspect the problem is because of the pbkdf2 callback function. It returns
return exits.success(code: 404);andreturn exits.success(code: 200);I still have to learn the async environment so please if anyone have any reference it will be great! My solution now is to use bcrypt module as it supports async/ await.– adis
Nov 9 at 7:15