1

i'm trying to get the code from the url body with "req.query.code", but is empty and the url show perfectly the code, i don't know what happen, this is my server.js file:

app.get('/validate', async (req, res, next) => {
                if (!req.query.code || req.query.code != "") {
                    console.log(clc.red(`Error: No code provided`));
                    res.send(`Error: The code is missing, please check the documentation`);
                    return;
                }
                else {
                    console.log(req.query.code);
                }
}

And when i saw the error, the url have the code.

http://xxxxxxxx:3001/validate?code=xxxxxxxxxxa64779xxxxxe42fe16xx8063xxxx2xxxx
1
  • Read your code out loud "If code is not truthy or code is not an empty string." Commented May 26, 2022 at 12:52

1 Answer 1

1

You have problem in your if condition in or operator in second condition you're checking for non-empty req.query.code because of which the if block is getting executed try this

            if (!req.query.code || req.query.code === "") 
               
                
Sign up to request clarification or add additional context in comments.

1 Comment

Bro, 1 hour searching the issue hahaha, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.