title: Unhandled Promise Rejection Warning Error
body: <p><strong>ERROR</strong></p>
  <blockquote>
  <p>(node:39756) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
  at ServerResponse.setHeader (_http_outgoing.js:561:11)
  at ServerResponse.header (C:\Users\elegm\OneDrive\Рабочий стол\animflex\api\node_modules\express\lib\response.js:771:10)
  at ServerResponse.send (C:\Users\elegm\OneDrive\Рабочий стол\animflex\api\node_modules\express\lib\response.js:170:12)
  at ServerResponse.json (C:\Users\elegm\OneDrive\Рабочий стол\animflex\api\node_modules\express\lib\response.js:267:15)
  at C:\Users\elegm\OneDrive\Рабочий стол\animflex\api\routes\auth.js:43:25
  at processTicksAndRejections (internal/process/task_queues.js:95:5)</p>
  </blockquote>
  <blockquote>
  <p>(Use <code>node --trace-warnings ...</code> to show where the warning was created)
  (node:39756) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag <code>--unhandled-rejections=strict</code> (see <a href="https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode" rel="nofollow noreferrer">https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode</a>). (rejection id: 1)
  (node:39756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.</p>
  </blockquote>
  <p>Here's my code</p>
  <pre><code>router.post(&quot;/login&quot;, async (req, res) =&gt; {
      try {
          const user = await User.findOne({ email: req.body.email });
          if (!user) {
              res.status(401).json(&quot;Something went wrong!&quot;);
          }
          const bytes = CryptoJS.AES.decrypt(user.password,
              process.env.SECRET_KEY);
          const originalPassword = bytes.toString(CryptoJS.enc.Utf8);
  
          if (originalPassword !== req.body.password) {
              res.status(401).json(&quot;Something went wrong!&quot;);
          }
  
          res.status(200).json(user);
      } catch (err) {
          res.status(500).json(err)
      }
  });
  
  module.exports = router;```
  </code></pre>