<?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: MD Tarekul Islam Sabbir</title>
    <description>The latest articles on DEV Community by MD Tarekul Islam Sabbir (@tisabbir).</description>
    <link>https://dev.to/tisabbir</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%2F2968823%2F5407dad7-06e3-4086-84aa-e263f9d60143.png</url>
      <title>DEV Community: MD Tarekul Islam Sabbir</title>
      <link>https://dev.to/tisabbir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tisabbir"/>
    <language>en</language>
    <item>
      <title>How I Fixed My Broken Signup Flow (And What It Taught Me)</title>
      <dc:creator>MD Tarekul Islam Sabbir</dc:creator>
      <pubDate>Fri, 28 Mar 2025 06:57:28 +0000</pubDate>
      <link>https://dev.to/tisabbir/how-i-fixed-my-broken-signup-flow-and-what-it-taught-me-4140</link>
      <guid>https://dev.to/tisabbir/how-i-fixed-my-broken-signup-flow-and-what-it-taught-me-4140</guid>
      <description>&lt;p&gt;You know that moment when your code &lt;em&gt;should&lt;/em&gt; work, but it's silently failing? Yeah, that was me last week. I built a user signup API, and it kept throwing vague errors like &lt;em&gt;"Something went wrong"&lt;/em&gt; with no details. Super helpful, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Breaking Point
&lt;/h2&gt;

&lt;p&gt;I finally saw this in my logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeError: Cannot read properties of undefined (reading 'collection')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Turns out, my database connection wasn't actually &lt;em&gt;connecting&lt;/em&gt;. I'd forgotten the critical &lt;code&gt;await client.connect()&lt;/code&gt;—oops. My &lt;code&gt;connectDB()&lt;/code&gt; function was basically a fancy no-op.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Went Wrong
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ghost Errors&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My &lt;code&gt;try/catch&lt;/code&gt; swallowed errors instead of passing them up&lt;/li&gt;
&lt;li&gt;Result: Empty &lt;code&gt;error: {}&lt;/code&gt; responses. &lt;em&gt;Cool. Very descriptive.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;HTTP Codes Gone Wild&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I used &lt;code&gt;304 Not Modified&lt;/code&gt; for existing users (🤦‍♂️)&lt;/li&gt;
&lt;li&gt;Reality check: &lt;code&gt;304&lt;/code&gt; is for caching. &lt;code&gt;409 Conflict&lt;/code&gt; is the correct "user exists" code&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Security? What Security?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passwords were flying in plaintext&lt;/li&gt;
&lt;li&gt;Zero input validation. &lt;em&gt;"What's an injection attack?"&lt;/em&gt; – Me, before Google&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How I Fixed It
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Database Connection Bootcamp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added &lt;code&gt;await client.connect()&lt;/code&gt;. &lt;em&gt;Shocking, I know.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Cached the connection so it doesn't re-connect every request&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Error Handling That Doesn't Suck&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Started logging errors with &lt;code&gt;console.error&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Returned actual error messages instead of &lt;code&gt;{}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;HTTP Codes That Make Sense&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;201 Created&lt;/code&gt; for new users&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;409 Conflict&lt;/code&gt; for duplicates&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;500&lt;/code&gt; only for &lt;em&gt;real&lt;/em&gt; server meltdowns&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Basic Security Hygiene&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added &lt;code&gt;bcrypt&lt;/code&gt; for password hashing&lt;/li&gt;
&lt;li&gt;Validated emails (no more &lt;code&gt;"not_an_email"&lt;/code&gt; signups)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Debugging 101:&lt;/strong&gt; Isolate the damn issue. Test DB connections separately&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP Codes Matter:&lt;/strong&gt; A wrong status code confuses everyone (including future you)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never Trust User Input:&lt;/strong&gt; Validate early, hash passwords, and sanitize everything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Moral of the Story?&lt;/strong&gt;&lt;br&gt;
If your code fails silently, you're in for a bad time. Log errors, use proper status codes, and &lt;em&gt;always&lt;/em&gt; secure user data. Now my signup flow actually works—and doesn't embarrass me. 🎉&lt;/p&gt;

&lt;p&gt;&lt;em&gt;— MD Tarekul Islam Sabbir, slightly wiser than last week&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9w0eyj7k2cxwiuxfs8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9w0eyj7k2cxwiuxfs8q.png" alt="User Signup Flow Diagram" width="800" height="1506"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>learning</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
