<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ilenterman</title>
    <description>The latest articles on DEV Community by ilenterman (@ilenterman).</description>
    <link>https://dev.to/ilenterman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F435861%2Fc7715479-8e94-421f-9d5f-da0f2320e74c.png</url>
      <title>DEV Community: ilenterman</title>
      <link>https://dev.to/ilenterman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ilenterman"/>
    <language>en</language>
    <item>
      <title>Why is my promise not resolving correctly?</title>
      <dc:creator>ilenterman</dc:creator>
      <pubDate>Mon, 20 Jul 2020 03:02:56 +0000</pubDate>
      <link>https://dev.to/ilenterman/why-is-my-promise-not-resolving-correctly-ach</link>
      <guid>https://dev.to/ilenterman/why-is-my-promise-not-resolving-correctly-ach</guid>
      <description>&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.addUser = async (req, res) =&amp;gt; {
  const { username, email, password } = req.body;
  //hash password
  const password_hash = await hashPassword(password);
    //check whitelist
    this.checkWhitelist(email).then( function(response) {
      if (response) {
        console.log("RESOLVED TRUE")
        //POST user to Airtable
        new Promise(function(resolve, reject) {
          return usersTable.create(
            {
              email,
              username,
              password_hash,
              "email_verified":"false"
            },
            function(err) {
              if (err) {
                resolve(false);
                console.error(err);
                res.send({
                  "Success":false,
                  "responseCode":502,
                })
              } resolve(true);
              res.send({
                "Success":true,
                "responseCode":200,
              });
              }
            ).then( function(response) {
              if (response) {
                const EMAIL_SECRET = "xxxxxxxxxxx";
                jwt.sign(
                  {
                    'username': username,
                  },
                  EMAIL_SECRET,
                  {
                    expiresIn: '1d',
                  },
                  (err, emailToken) =&amp;gt; {
                    const url = `http://localhost:3000/confirmation/${emailToken}`;

                    transporter.sendMail({
                      to: args.email,
                      subject: 'Confirm Email',
                      html: `Please click this email to confirm your email: &amp;lt;a href="${url}"&amp;gt;${url}&amp;lt;/a&amp;gt;`,
                    });
                  }
                )
              }
            })
      })} else {
        console.log('RESOLVED FALSE')
        res.send({
          "Success":false,
          "responseCode":403
        })
      }
    }
  )}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For some reason, the promise I created at usersTable.create is not resolving correctly. When I call .then() after, I get the error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'then' of undefined.&lt;/p&gt;

&lt;p&gt;For context, this is the user registration flow for a webapp. First, the pass is hashed, then the email is check against a whitelist (so far this logic is working). Now I just need to verify the email, but can't get the .then() to call correctly.-&lt;/p&gt;

&lt;p&gt;What's going on?&lt;/p&gt;

</description>
      <category>help</category>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
