<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jay Mehta on Medium]]></title>
        <description><![CDATA[Stories by Jay Mehta on Medium]]></description>
        <link>https://medium.com/@jaymehta20?source=rss-fc4931302c2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BT9jnAKyWegrkT0i8JNhpg.jpeg</url>
            <title>Stories by Jay Mehta on Medium</title>
            <link>https://medium.com/@jaymehta20?source=rss-fc4931302c2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:26:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaymehta20/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA["Next Auth on AWS EC2: Solving Redirect Issues with Trust Host and AUTH_URL."]]></title>
            <link>https://medium.com/intelliconnectq-engineering/next-auth-on-aws-ec2-solving-redirect-issues-with-trust-host-and-auth-url-fec7a09ef9c3?source=rss-fc4931302c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fec7a09ef9c3</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[authjs]]></category>
            <category><![CDATA[nextauth]]></category>
            <dc:creator><![CDATA[Jay Mehta]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 12:45:43 GMT</pubDate>
            <atom:updated>2024-03-23T15:43:25.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CYnYIlH8waiUDckmaid5UA.jpeg" /></figure><h3>Understanding the Issue</h3><p>The redirection to localhost post-login arises <strong>from the default behaviour of Next Auth</strong>, which may not align with the custom server setup on AWS EC2. This disparity can lead to a troubling user experience and potential security vulnerabilities. To tackle this, configuring Next Auth to trust the host and explicitly specifying the authentication URL is imperative.</p><h3>Resolving the Redirect Issue</h3><p>To rectify the redirect to localhost problem, follow these steps:</p><ol><li><strong>Trust Host Configuration</strong>: In your Next.js project, add trustHost: true to your Next Auth configuration. This setting instructs Next Auth to trust the host provided in the request headers, preventing unexpected redirects to localhost.</li><li><strong>Environment Variable Setup:</strong> Define an environment variable AUTH_URL=yourdomain.com/api/auth in your project. This step ensures that Next Auth consistently uses the specified authentication URL, avoiding redirection inconsistencies.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6szHkJwYxboCp5dceaRlLg.png" /><figcaption>auth.ts code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7f8TPKeL2aqvm0RvRUAaOA.png" /><figcaption>env code</figcaption></figure><p>By incorporating these adjustments, you can seamlessly integrate Next Auth with your custom AWS server while mitigating the redirect to localhost issue.</p><p><em>Credits: I thank my colleague </em><a href="https://medium.com/u/fa82ffb2a3df"><em>Pavan Patil</em></a><em> from our IT Infra &amp; DevOps Team for collaborating to find the fix.</em></p><h3>About Intelliconnect</h3><blockquote><em>We at Intelliconnect work with leaders who have ambitious plans to grow their businesses. Our custom solutions</em></blockquote><blockquote><em>1. Enable autonomous decision-making, reducing and ultimately eliminating the need for human intervention.<br>2. Provide signals &amp; insights that enable swift action.<br>3. Empower teams with real-time information for strategic and operational decision-making, driving the development of a data-driven culture.4. Are personalized for the role and easy &amp; seamless to use ie efforts by the user are zero or minimum</em></blockquote><blockquote><em>Connect with us at solutions[at]intelliconnectq.com</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fec7a09ef9c3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intelliconnectq-engineering/next-auth-on-aws-ec2-solving-redirect-issues-with-trust-host-and-auth-url-fec7a09ef9c3">&quot;Next Auth on AWS EC2: Solving Redirect Issues with Trust Host and AUTH_URL.&quot;</a> was originally published in <a href="https://medium.com/intelliconnectq-engineering">IntelliconnectQ Analytics Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Fixing Hydration Issues in Next.js and Zustand: A Simple Solution”]]></title>
            <link>https://medium.com/intelliconnectq-engineering/fixing-hydration-issues-in-next-js-and-zustand-a-simple-solution-bd0a8deff6cc?source=rss-fc4931302c2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd0a8deff6cc</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[hydration]]></category>
            <category><![CDATA[zustand]]></category>
            <dc:creator><![CDATA[Jay Mehta]]></dc:creator>
            <pubDate>Tue, 09 May 2023 06:58:19 GMT</pubDate>
            <atom:updated>2023-05-09T06:58:19.614Z</atom:updated>
            <content:encoded><![CDATA[<p>As web developers, we often face the issue of hydration when working with frameworks such as Next.js and state management tools like Zustand. Hydration refers to the process of rendering the HTML page and loading the JavaScript bundle in the browser, and it is crucial for the proper functioning of our web application. In this blog post, we’ll look at how to fix hydration issues in Next.js and Zustand.</p><figure><img alt="A bear playing guitar" src="https://cdn-images-1.medium.com/max/798/0*jfotppBqgzvZv3zP.jpeg" /></figure><h3>Introduction</h3><p>When we use Next.js with Zustand, we can face hydration issues. This happens because the server renders the HTML with some initial state, and then the client-side JavaScript takes over and initialises the Zustand store. If the initial state is different from the state that the client-side JavaScript initializes, it can cause inconsistencies in our application.</p><h3>The solution</h3><p>To fix this issue, we can create a simple component that waits for the Next.js hydration to complete before rendering our application. We can call this component HydrationZustand. Here&#39;s the code:</p><pre>import { useEffect, useState } from &quot;react&quot;<br><br>const HydrationZustand = ({ children }) =&gt; {<br>  const [isHydrated, setIsHydrated] = useState(false)<br><br>  // Wait till Next.js rehydration completes<br>  useEffect(() =&gt; {<br>    setIsHydrated(true)<br>  }, [])<br><br>  return &lt;&gt;{isHydrated ? &lt;div&gt;{children}&lt;/div&gt; : null}&lt;/&gt;<br>}<br><br>export default HydrationZustand</pre><p>This component waits for the Next.js rehydration to complete by using the useEffect hook. Once the rehydration is complete, it sets the isHydrated state to true, which allows the children to be rendered.</p><p>Next, we need to wrap our application with the HydrationZustand component. We can do this in our _app.js file. Here&#39;s the code:</p><pre>import &quot;../scss/style.default.scss<br>import Layout from &quot;../components/Layout&quot;<br>import HydrationZustand from &quot;./hydrationZustand&quot;<br><br>function App({ Component, pageProps }) {<br>  return (<br>    &lt;HydrationZustand&gt;<br>      &lt;Layout {...pageProps}&gt;<br>        &lt;Component {...pageProps} /&gt;<br>      &lt;/Layout&gt;<br>    &lt;/HydrationZustand&gt;<br>  )<br>}<br><br>export default App</pre><p>Here, we’re wrapping our Layout component with HydrationZustand. This ensures that our application is only rendered once the hydration is complete. Any state management tool, including Zustand, will work properly with this approach.</p><h3>Examples</h3><ol><li>Inconsistent UI: If the initial state of the application on the server side and the client side is different, it can cause UI bugs or inconsistencies. For example, a button may appear as enabled on the server side, but when the client-side JavaScript takes over, it may be disabled because of a different state.</li><li>Broken functionality: In some cases, hydration issues can cause the application to crash or break functionality. For instance, if the server-side rendering and client-side rendering are inconsistent, it can lead to errors such as “undefined is not a function” or “cannot read property of null”.</li><li>Performance issues: Hydration issues can also lead to performance problems. For example, if the server-side rendering and client-side rendering are inconsistent, the browser may need to render the same components multiple times, leading to unnecessary re-renders and slower page load times.</li></ol><p>By understanding these examples, developers can see how important it is to properly manage hydration in their Next.js and Zustand applications.</p><h3>Conclusion</h3><p>In conclusion, fixing hydration issues in Next.js and Zustand is essential for the proper functioning of our web applications. By using the HydrationZustand component, we can ensure that our application is rendered only after the Next.js rehydration is complete. This simple fix can save us from a lot of headaches and inconsistencies in our application.</p><p><strong>References</strong></p><ul><li>Next.js documentation: <a href="https://nextjs.org/docs/getting-started">https://nextjs.org/docs/</a></li><li>Zustand documentation: <a href="https://docs.pmnd.rs/zustand">https://docs.pmnd.rs/zustand</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd0a8deff6cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intelliconnectq-engineering/fixing-hydration-issues-in-next-js-and-zustand-a-simple-solution-bd0a8deff6cc">“Fixing Hydration Issues in Next.js and Zustand: A Simple Solution”</a> was originally published in <a href="https://medium.com/intelliconnectq-engineering">IntelliconnectQ Analytics Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>