You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typically this is a prime use case for promises (but know that you only dabbled with that a little this week). This is a bit tricky, and hard to test, what you'll want to do here is create new functions that you pass in as arguments instead of nesting.
eg.
constcreateUserHandler=(err,res)=>{if(err){response.writeHead(500,{'content-type': 'text/html'});response.end('Oops! There was a problem');}else{letuserIdName=JSON.parse(res);constcookie=sign(userIdName,process.env.SECRET);response.writeHead(302,{'Location': '/main','Set-Cookie': `jwt=${cookie}; HttpOnly`});response.end('You have succesfully signed in');}}if(validateUser(userData)===true){checkUser(userData,(err,res)=>{if(err){response.writeHead(500,{'content-type': 'text/html'});response.end('Oops! There was a problem');}elseif(res===1){response.writeHead(401,{'content-type': 'text/html'})response.end(`Username: ${userData.username} already exists, try logging in`);}elseif(res===0){genHashedPassword(userData,(err,result)=>{if(err){response.writeHead(500,{'content-type': 'text/html'});response.end('Oops! There was a problem');}else{createUser(result,createUserHandler);}});}});
The text was updated successfully, but these errors were encountered:
https://github.com/fac-12/BudgetPlanner/blob/master/src/handler.js#L91-L126
Typically this is a prime use case for
promises
(but know that you only dabbled with that a little this week). This is a bit tricky, and hard to test, what you'll want to do here is create new functions that you pass in as arguments instead of nesting.eg.
The text was updated successfully, but these errors were encountered: