<?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: Hasnain Jaffer</title>
    <description>The latest articles on DEV Community by Hasnain Jaffer (@hasnainjaffer).</description>
    <link>https://dev.to/hasnainjaffer</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4027395%2F55655aeb-e670-4b84-916a-2fb36c61ae4a.jpg</url>
      <title>DEV Community: Hasnain Jaffer</title>
      <link>https://dev.to/hasnainjaffer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hasnainjaffer"/>
    <language>en</language>
    <item>
      <title>CORS + Auth Worked Perfectly Locally, Then Broke the Moment I Deployed (Here's Why)</title>
      <dc:creator>Hasnain Jaffer</dc:creator>
      <pubDate>Mon, 13 Jul 2026 14:29:58 +0000</pubDate>
      <link>https://dev.to/hasnainjaffer/cors-auth-worked-perfectly-locally-then-broke-the-moment-i-deployed-heres-why-ee3</link>
      <guid>https://dev.to/hasnainjaffer/cors-auth-worked-perfectly-locally-then-broke-the-moment-i-deployed-heres-why-ee3</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7x50uuq2ypurf82n652a.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7x50uuq2ypurf82n652a.png" alt=" " width="800" height="441"&gt;&lt;/a&gt;I ran into this bug recently and it took me longer to fix than I'd like to admit: my React + Express app worked flawlessly on localhost, but the moment I deployed it, authenticated requests started silently failing. No errors in my own code — just requests that looked like they went out, but the backend never seemed to receive the session/token.&lt;br&gt;
The setup&lt;/p&gt;

&lt;p&gt;React frontend and Express backend deployed to separate origins (different domains/subdomains)&lt;br&gt;
Auth relying on a cookie (or JWT sent with credentials) set by the backend&lt;br&gt;
Locally, both ran on localhost with different ports, which browsers treat more leniently&lt;/p&gt;

&lt;p&gt;What actually happened&lt;br&gt;
Once frontend and backend were on genuinely different origins in production, a few things I'd gotten away with locally stopped working:&lt;/p&gt;

&lt;p&gt;My CORS config allowed origin: '*' — which silently breaks anything using credentials, since browsers won't send cookies/auth headers when the origin is a wildcard.&lt;br&gt;
The cookie itself wasn't configured for cross-site use — no SameSite=None; Secure, which most browsers now require for any cookie sent across origins over HTTPS.&lt;br&gt;
On the frontend, requests weren't explicitly sending credentials (credentials: 'include' in fetch, or withCredentials: true in axios).&lt;/p&gt;

&lt;p&gt;Locally, same-origin-ish behavior papered over all three problems at once.&lt;br&gt;
The fix&lt;/p&gt;

&lt;p&gt;Set CORS to an explicit origin (not *) and credentials: true on the Express side&lt;br&gt;
Set the cookie with SameSite=None; Secure so browsers allow it cross-site&lt;br&gt;
Explicitly send credentials on every authenticated request from the frontend&lt;/p&gt;

&lt;p&gt;Once all three were aligned, everything that had been "randomly failing" in production started working immediately.&lt;br&gt;
Takeaway: if your auth works locally but silently fails after deploy, check CORS origin config, cookie SameSite/Secure attributes, and whether the frontend is actually sending credentials — together, not just one of them.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
