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.










share|improve this question





















  • 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














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.










share|improve this question





















  • 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












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 14:18









adis

11019




11019











  • 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















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












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






share|improve this answer




















  • 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




    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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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






share|improve this answer




















  • 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




    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














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






share|improve this answer




















  • 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




    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












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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 18:20









streleck

26019




26019











  • 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




    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






  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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














































































Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages