<?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 urboiFox on Medium]]></title>
        <description><![CDATA[Stories by urboiFox on Medium]]></description>
        <link>https://medium.com/@urboifox?source=rss-3707de0c9d55------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LVtXMB5KuTVeef3JSNpNHw.jpeg</url>
            <title>Stories by urboiFox on Medium</title>
            <link>https://medium.com/@urboifox?source=rss-3707de0c9d55------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 19:33:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@urboifox/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[Lens.js: Open Source Monitoring Tool for the Node.js World]]></title>
            <link>https://medium.com/@urboifox/lens-js-open-source-monitoring-tool-for-the-node-js-world-2c954bbf4f59?source=rss-3707de0c9d55------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c954bbf4f59</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[urboiFox]]></dc:creator>
            <pubDate>Sat, 30 Aug 2025 15:27:08 GMT</pubDate>
            <atom:updated>2025-08-30T15:56:16.583Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oF1hpw8KHsCnhkhhB7pwBQ.png" /><figcaption>Lens.js</figcaption></figure><h3>The Problem: Node.js Lacks a Telescope</h3><p>Monitoring the requests hitting your backend application is essential for faster development and easier debugging. <a href="https://laravel.com/docs/12.x/telescope"><strong>Laravel Telescope</strong></a> has long been one of the best tools for this in the PHP world. But what about <strong>Node.js</strong>? We couldn’t find an equivalent tool that provides the same functionality in the Node.js ecosystem. And that’s why we decided to build <a href="https://lensjs.vercel.app/"><strong>Lens</strong></a>.</p><p>While it’s possible to create a framework-specific monitoring tool or roll your own custom UI with logged events, those solutions are often too narrow. What if you could have a tool that works across the board, regardless of the framework? One that’s focused on Node.js and not tied to a specific framework?</p><p>This is where <a href="https://lensjs.vercel.app/"><strong>Lens</strong></a> comes in.</p><h3>What is Lens?</h3><p>Lens is a <strong>framework-agnostic</strong> monitoring tool designed for <strong>Node.js</strong> applications. It provides insights into the requests and queries of your application through a modern UI, making it easy to track what’s happening behind the scenes without constantly checking the console logs.</p><p>While there are many great frameworks, having a tool that works across all of them can be a challenge. Lens is designed to break through those boundaries, giving you flexibility whether you’re using <strong>Express</strong>, <strong>Adonis.js</strong>, or anything else built on Node.js.</p><h3>Framework-Agnostic by Design</h3><p>Lens has adapters for <strong>Express</strong> and <strong>Adonis.js</strong>. But since Lens is framework-agnostic, it will work with any Node.js application via the core package.</p><p>We designed Lens to be as flexible as possible. So even if your current framework isn’t supported yet, you can still benefit from the core functionality. We plan to add more adapters for other frameworks in the future. If you’re using a framework that Lens doesn’t support, or if you want to help add support for one, feel free to contribute!</p><h3>Core Features: Requests, Queries, and Beyond</h3><p>Currently, the core package provides two primary features:</p><ul><li><strong>Request Tracking</strong></li><li><strong>Query Tracking</strong></li></ul><p>But this is just the beginning! We’re working on additional features like tracking emails, exceptions, cache, logs, and more. Expect frequent updates with new releases as we continue to enhance the tool.</p><h3>Getting Started With Lens.js</h3><p>Setting up <a href="https://lensjs.vercel.app/"><strong>Lens</strong></a> with its adapters is quick and simple. However, if there’s no adapter for your framework yet, don’t worry! The <a href="https://lensjs.vercel.app/getting-started/quick-start.html">documentation</a> covers everything you need to use the core package with any Node.js application.</p><p>You can read the full setup instructions and start using <a href="https://lensjs.vercel.app/"><strong>Lens</strong></a> from the <a href="https://lensjs.vercel.app/getting-started/quick-start.html">official documentation</a>.</p><h3>What’s Next?</h3><p>The journey with <strong>Lens</strong> is just beginning, and we’d love to hear from you. If you encounter any issues, please open an issue on the <a href="https://github.com/lensjs/lens">official GitHub repository</a>. If you’re interested in contributing, we welcome pull requests for new adapters or features.</p><p>We also encourage you to share your thoughts and feedback in the comments section. Your input is invaluable as we continue to improve the tool.</p><p>Thank you for reading, and we hope you enjoy using <strong>Lens</strong>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c954bbf4f59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From React to Svelte: A simpler faster way to build For the web]]></title>
            <link>https://medium.com/@urboifox/from-react-to-svelte-a-simpler-faster-way-to-build-for-the-web-b937f6861f39?source=rss-3707de0c9d55------2</link>
            <guid isPermaLink="false">https://medium.com/p/b937f6861f39</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[svelte]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[urboiFox]]></dc:creator>
            <pubDate>Tue, 06 May 2025 17:24:04 GMT</pubDate>
            <atom:updated>2025-05-06T22:30:39.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LDOfNXOecD2CMXkTc3Uqhg.png" /><figcaption>Svelte and React</figcaption></figure><p>For a long time, React and Next.js were my primary tools for creating web applications. Their widespread use, strong community support, and flexible component system made them a reliable choice. However, over time, I began to notice some drawbacks. I had to deal with too much repetitive code, complicated ways to manage data, and a feeling that I was spending more time working around the framework than building my project. I wanted a tool that made development easier and faster without losing the ability to create high-quality, efficient applications.</p><p>That’s when I came across Svelte. I first learned about it through <a href="https://youtube.com/@fireship?si=rlU0bbMUlMb8AbT3">Fireship</a> videos and decided to explore it further. What I discovered was a framework that tackled many of the issues I faced with React while making development enjoyable again. This article reflects my experience with Svelte version 5, the latest version at the time of writing, though my initial introduction was with an earlier version. Let’s start by looking at the challenges I encountered with React before explaining why Svelte became my preferred choice.</p><h3>Challenges I Faced with React</h3><h3>Slow Performance in Complex Interfaces</h3><p>In one project, I worked on an employee management system that included a permissions page. This page had about 50 permissions, each with three checkboxes — edit, delete, and view — totaling 150 checkboxes. Each checkbox was linked to a state, and whenever a user clicked one, the page took around two seconds to update. There was also a search box to filter permissions, but typing in it caused a delay with every letter, making the experience frustrating for users.</p><p>The issue stemmed from how React updates the screen. When data changes, React compares a virtual version of the page (virtual dom) with the real one and redraws anything that’s different. And with lots of interactive parts, this can slow things down. Svelte, on the other hand, updates only the exact pieces that change, thanks to its signal-based system. This makes it much faster, even when handling hundreds of inputs like in my permissions page.</p><h3>Larger File Sizes Affecting Load Times</h3><p>Another problem with React was the size of the files it created. Even a basic React app comes with about 50–60 KB of code, mostly because of the virtual DOM and other built-in features.</p><p>Svelte takes a different approach — it turns your code into plain, efficient JavaScript during the build process. For a simple app, this can result in files as small as 3 KB. Without the extra baggage of a virtual DOM, Svelte apps load quickly and run smoothly.</p><h3>Too Much Setup and Rules</h3><p>React’s way of doing things is powerful, but it often requires a lot of extra steps. Managing data, setting up navigation, or fetching information from a server meant writing more code than I’d like — or constantly checking the docs to do. Even with Next.js, which simplifies some of this. It started to feel like I was working for the tool instead of the tool working for me.</p><p>React makes you feel it’s the only way to build software.</p><h3>What Makes Svelte Different and Better</h3><p>Here’s why Svelte has become my go-to framework for web development.</p><h3>Easy Data Management</h3><p>In React, keeping track of data can get complicated. You might use useState for small things, but for bigger scenarios, you could end up needing the Context API or a separate library like Redux or Zustand. Each option adds more steps and decisions. Svelte makes this much simpler with it’s ability to make a state global. For example, to create a shared piece of data in Svelte 5, you just write:</p><pre>// File: lib/store.svelte.ts<br>export const myStore = $state({ items: [] });</pre><p>You can use this store anywhere in your app, and it updates automatically when the data changes. It’s like having a lightweight version of Redux built right into Svelte — no extra setup needed. This cuts down on complexity and makes things predictable.</p><p>You don’t work with other libraries, or need to adapt to each project’s state management library. it’s all Svelte.</p><h3>Simpler Input Handling</h3><p>Forms in React require you to write code to track every change in an input field. For example, to create a controlled input, you’d need something like this:</p><pre>const [name, setName] = useState(&quot;&quot;);<br>&lt;input type=&quot;text&quot; value={name} onChange={(e) =&gt; setName(e.target.value)} /&gt;</pre><p>This gets repetitive fast, especially with lots of fields. Svelte makes it easier with it’s built in two-way data binding:</p><pre>&lt;script&gt;<br>  let name = $state(&quot;&quot;);<br>&lt;/script&gt;</pre><pre>&lt;input type=&quot;text&quot; bind:value={name} /&gt;</pre><p>The bind:value line connects the input to the name variable directly. When you type, name updates, and if name changes elsewhere, the input updates too. It’s a cleaner, faster way to handle forms.</p><p>You also have bind:checked and bind:group and you can even make a prop bindable using the $bindable rune.But i won’t explain it because this post will be so long. You get the idea.</p><h3>Handling Nested Data Without Extra Work</h3><p>In React, updating data that’s layered — like an object inside an object — can be tricky. You have to make a copy of the data first, like this:</p><pre>const [data, setData] = useState({ location: { country: { city: &quot;New York&quot; } } });<br>const newData = { ...data };<br>newData.location.country.city = &quot;Boston&quot;;<br>setData(newData);</pre><p>This is not predictable, because if you change the state directly it wont work, takes extra effort and can lead to mistakes. Svelte handles this automatically with its reactive system. You can just write:</p><pre>&lt;script&gt;<br>  let data = $state({ location: { country: { city: &quot;New York&quot; } } });<br>&lt;/script&gt;</pre><pre>&lt;button onclick={() =&gt; data.location.country.city = &quot;Boston&quot;}&gt;Change City&lt;/button&gt;</pre><p>Svelte updates the page efficiently without you needing to manage copies. This makes working with complicated data feel natural and straightforward.</p><h3>Built-In Motion and Effects</h3><p>Adding animations in React usually means bringing in extra tools like Framer Motion or GSAP, which add more code to download and learn. Svelte has animations built in, so you can do things like this:</p><pre>&lt;script&gt;<br>  import { fade } from &#39;svelte/transition&#39;;<br>  let show = $state(true);<br>&lt;/script&gt;</pre><pre>{#if show}<br>  &lt;div transition:fade&gt;This fades in and out&lt;/div&gt;<br>{/if}</pre><pre>&lt;button onclick={() =&gt; show = !show}&gt;Toggle&lt;/button&gt;</pre><p>This creates a smooth fade effect with almost no effort. Svelte offers other options like sliding or scaling, and they all work with the framework’s system for updating the page. It’s a lightweight way to make your app feel more polished without extra tools.</p><h3>A Better Experience for Developers</h3><p>Svelte feels designed to help you, not hold you back. You can build any web app with any framework. But the developer experience for me is key. Even though Svelte’s performance is huge, but most benefits you will see people talking about is the developer experience. For me it’s something you wont know how it feels until you try it.</p><h3>Why Svelte Wins for Me</h3><p>I don’t think i can pack all svelte features over react in one post, but i guess you get the point now.<br>Svelte solves the performance problems I saw in React, keeps file sizes small for faster loading, and simplifies tasks like managing data and adding effects. Beyond the technical benefits, it brings back the fun of creating web applications. I spend less time fighting with the framework and more time bringing my ideas to life.</p><p>I recommend trying Svelte. It’s a great tool that feels approachable and efficient — a combination that’s hard to beat in today’s web development world.</p><p>Thanks for reading till the end.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b937f6861f39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication in Next.js with an External Backend]]></title>
            <link>https://medium.com/@urboifox/authentication-in-next-ajs-with-an-external-backend-262fc2748158?source=rss-3707de0c9d55------2</link>
            <guid isPermaLink="false">https://medium.com/p/262fc2748158</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[full-stack-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[authorization]]></category>
            <dc:creator><![CDATA[urboiFox]]></dc:creator>
            <pubDate>Sat, 01 Mar 2025 13:32:27 GMT</pubDate>
            <atom:updated>2025-03-19T18:25:21.030Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zMmpajvaj8l_mEqG7If-8g.png" /></figure><p>Meta-frameworks like Next.js are a superset of other frameworks. They have an organized structure and provide various methods and tools that make development more efficient.</p><p>Making full-stack development easier in general.</p><p>If you are a front-end developer working in an environment where the back-end uses a different technology, you should (most of the time) go with a client SPA library or framework like React, Svelte etc.</p><p>But what if you’re working on a website that needs some meta frameworks features like SSG, ISR, or prerendering, and the back-end is already done with something like PHP?</p><p>Or maybe another scenario, where a client comes to you with an API ready, and wants a Nextjs website for some reason.</p><p>Well, you would just call the external back-end APIs on the Nextjs server, instead of querying a database directly, and all features will work without a problem.</p><p>There will be a problem once the website needs authentication.</p><p>Authentication without meta-frameworks is fairly straightforward:</p><ul><li>You send your login request</li><li>receive a token</li><li>store it in state</li><li>then send it in every request using axios interceptors or just send it manually.</li></ul><p>And you are done.</p><p>In meta frameworks, if you use the same approach you won’t be able to fetch data on the server, because the token is only accessible to the client through your state. So your app will behave just like an SPA anyway.</p><p>You can, however, set the token in cookies from the client and access it from the server.</p><p>But it won’t be an httpOnly cookie, since you are setting it from the client. And this will make your website vulnerable to CSRF attacks.</p><p>So if you care about security this approach won’t be ideal.</p><p>Ultimately, we want to store the token in two places:</p><ol><li>as an httpOnly cookie</li><li>In our app memory (state)</li></ol><p>So we can access it from both client and server. This way we can fetch data from anywhere, stay secured, and keep the framework’s features.</p><h3>The solution?</h3><p>Since we wanna set an httpOnly cookie in our app, based on <a href="https://nextjs.org/docs/app/api-reference/functions/cookies#setting-a-cookie">Nextjs docs</a>, we have to make our login request go through an API route handler, or a server action.</p><ol><li>First, let’s create our API route handler.</li></ol><pre>// src/app/api/login/route.tsx<br><br>import { API_URL } from &quot;@/constants&quot;;<br>import { cookies } from &quot;next/headers&quot;;<br>import { NextResponse } from &quot;next/server&quot;;<br><br>// This route acts as a middleware between you and your backend server<br>export async function POST(request: Request) {<br>    const cookieStore = await cookies();<br>    const formData = await request.formData();<br>    const payload = Object.fromEntries(formData.entries());<br><br>    try {<br>        // login request to the original backend<br>        const res = await fetch(API_URL + &quot;/auth/login&quot;, {<br>            method: &quot;POST&quot;,<br>            headers: { &quot;Content-Type&quot;: &quot;application/json&quot; },<br>            body: JSON.stringify(payload)<br>        });<br>        const json = await res.json();<br><br>        if (res.ok) {<br>            cookieStore.set(&quot;token&quot;, json.data.token, {<br>                path: &quot;/&quot;,<br>                expires: new Date(json.data.token_expires_at),<br>                // We can set the token as an httpOnly cookie<br>                // now because we are on the server<br>                httpOnly: true,<br>                sameSite: &quot;lax&quot;,<br>                secure: process.env.NODE_ENV === &quot;production&quot;<br>            });<br>            // Optional: if your backend implements refresh token<br>            cookieStore.set(&quot;refreshToken&quot;, data.data.refresh_token, {<br>                path: &quot;/&quot;,<br>                expires: new Date(data.data.refresh_token_expires_at),<br>                httpOnly: true,<br>                sameSite: &quot;lax&quot;,<br>                secure: process.env.NODE_ENV === &quot;production&quot;<br>            });<br>        }<br><br>        // Return the same response as the external backend.<br>        return NextResponse.json(data, { status: res.status });<br>    } catch (err) {<br>        console.log(&quot;Error logging in:&quot;, err);<br>        return NextResponse.json({ message: &quot;Something went wrong&quot; }, { status: 500 });<br>    }<br>}</pre><p>2. Then make our login form that submits to it.</p><pre>// src/app/login/page.tsx<br><br>&quot;use client&quot;;<br>import { useState } from &quot;react&quot;;<br>import { toast } from &quot;sonner&quot;;<br>import { useAuthStore } from &quot;../store&quot;;<br>import { useRouter } from &quot;next/navigation&quot;;<br>import { Link } from &quot;@/i18n/routing&quot;;<br><br>export default function LoginForm() {<br>    const router = useRouter();<br><br>    const [errors, setErrors] = useState&lt;Record&lt;string, string[]&gt;&gt;({});<br>    const [loading, setLoading] = useState(false);<br>    // zustand store. You can use Redux, Recoil, or any other<br>    // state management method.<br>    const loginInState = useAuthStore((state) =&gt; state.login);<br><br>    async function handleSubmit(e: React.FormEvent&lt;HTMLFormElement&gt;) {<br>        e.preventDefault();<br>        const formData = new FormData(e.currentTarget);<br>        setErrors({});<br>        setLoading(true);<br><br>        // request to the API route we just created<br>        await fetch(&quot;/api/login&quot;, {<br>            method: &quot;POST&quot;,<br>            body: formData<br>        })<br>            .then(async (res) =&gt; {<br>                const data = await res.json();<br>                if (!res.ok) {<br>                    console.error(data);<br>                    if (data?.data) {<br>                        setErrors(data.data);<br>                    }<br>                    throw new Error(data?.message);<br>                }<br>                return data;<br>            })<br>            .then(({ data }) =&gt; {<br>                // If the login succeeds, store the user data, and token<br>                // in memory (state)<br>                loginInState(data.token, data.user);<br>                // then redirect the user to the home page<br>                router.push(&quot;/&quot;);<br>            })<br>            .catch((error) =&gt; {<br>                // if anything went wrong show a toast error<br>                toast.error(error?.message || &quot;Something went wrong&quot;);<br>                console.log(error)<br>            })<br>            .finally(() =&gt; {<br>                setLoading(false);<br>            });<br>    }<br><br>    return (<br>        &lt;form className=&quot;flex flex-col gap-4&quot; onSubmit={handleSubmit}&gt;<br>            &lt;input<br>                type=&quot;text&quot;<br>                name=&quot;email&quot;<br>                placeholder=&quot;Email&quot;<br>            /&gt;<br>           &lt;input<br>              type=&quot;password&quot;<br>              name=&quot;password&quot;<br>              placeholder=&quot;********&quot;<br>            /&gt;<br>            &lt;button type=&quot;submit&quot; disabled={loading}&gt;<br>                {loading ? &quot;Loading...&quot; : &quot;Login&quot;}<br>            &lt;/button&gt;<br>        &lt;/form&gt;<br>    );<br>}</pre><p>Now we have the token in both cookies and state, and it’s safe too!</p><p>The next step is to handle a couple of scenarios:</p><ul><li>When the user refreshes the page, the state is cleared. So we have to get the token and profile again from the server</li><li>Protecting routes based on login status</li></ul><p>3. To get the token and user initially, we will create another API route handler, to get the user profile:</p><pre>// src/app/api/profile/route.ts<br><br>import { API_URL } from &quot;@/constants&quot;;<br>import { refreshToken } from &quot;@/utils/refresh-token&quot;;<br>import { cookies } from &quot;next/headers&quot;;<br>import { NextResponse } from &quot;next/server&quot;;<br><br>export async function GET(request: Request) {<br>    const cookieStore = await cookies();<br>    let token = cookieStore.get(&quot;token&quot;)?.value;<br><br>    if (!token) {<br>      if (!cookieStore.get(&quot;refreshToken&quot;)?.value) {<br>        return NextResponse.json({ message: &quot;No user logged in&quot; }, { status: 200 });<br>      }<br>      // Optional: If you have a refresh token<br>      // get the new token and set it.<br>      const newTokenData = await refreshToken();<br>      if (!newTokenData) {<br>          cookieStore.delete(&quot;token&quot;);<br>          cookieStore.delete(&quot;refreshToken&quot;);<br>          return NextResponse.redirect(new URL(&quot;/login&quot;, request.url));<br>      }<br><br>      token = newTokenData.token;<br>      cookieStore.set(&quot;token&quot;, newTokenData.token, {<br>          path: &quot;/&quot;,<br>          expires: new Date(newTokenData.expires),<br>          httpOnly: true,<br>          sameSite: &quot;lax&quot;,<br>          secure: process.env.NODE_ENV === &quot;production&quot;<br>      });<br>    }<br><br>    try {<br>        // get the user profile from the external backend with the token<br>        const res = await fetch(API_URL + &quot;/auth/profile&quot;, {<br>            headers: {<br>                &quot;Content-Type&quot;: &quot;application/json&quot;,<br>                Authorization: `Bearer ${token}`<br>            }<br>        });<br><br>        const { data } = await res.json();<br>        // return the user, and token to the client to set them in state<br>        return NextResponse.json({ user: data, token }, { status: res.status });<br>    } catch {<br>        return NextResponse.json({ message: &quot;Something went wrong&quot; }, { status: 500 });<br>    }<br>}</pre><p>4. Then call this API route once our app loads using a provider.</p><pre>// src/providers/auth-provider.tsx<br><br>&quot;use client&quot;;<br>import { useEffect } from &quot;react&quot;;<br>import { useAuthStore } from &quot;./store&quot;;<br><br>export default function AuthProvider({ children }: { children: React.ReactNode }) {<br>    const loginInState = useAuthStore((state) =&gt; state.login);<br><br>    useEffect(() =&gt; {<br>        async function getUser() {<br>            const res = await fetch(&quot;/api/profile&quot;);<br>            const data = await res.json();<br>            if (data?.token &amp;&amp; data?.user) {<br>                loginInState(data.token, data.user);<br>            }<br>        }<br>        getUser();<br>    }, [loginInState]);<br><br>    return children;<br>}</pre><p>5. and then we just wrap our components with the AuthProvider</p><pre>import AuthProvider from &quot;@/providers/auth-provider&quot;;<br>import &quot;./globals.css&quot;;<br><br><br>interface Props {<br>  children: React.ReactNode;<br>}<br><br>export default async function RootLayout({ children }: Readonly&lt;Props&gt;) {<br>    return (<br>        &lt;html&gt;<br>            &lt;body&gt;<br>                &lt;AuthProvider&gt;{children}&lt;/Providers&gt;<br>            &lt;/body&gt;<br>        &lt;/html&gt;<br>    );<br>}</pre><p>6. The last step is to handle protected routes, and we can do that using the middleware file in Nextjs</p><pre>// src/middleware.ts<br><br>import { NextRequest, NextResponse } from &quot;next/server&quot;;<br><br>const AUTH_ROUTES = [&quot;/login&quot;, &quot;register&quot;];<br>const PRIVATE_ROUTES = [&quot;/dashboard&quot;, &quot;/admin&quot;];<br><br>export default async function middleware(req: NextRequest) {<br>    const token = req.cookies.get(&quot;refreshToken&quot;)?.value;<br>    const url = req.nextUrl.clone();<br>    const pathname = url.pathname;<br><br>    if (token &amp;&amp; AUTH_ROUTES.some((path) =&gt; pathname.startsWith(path))) {<br>        url.pathname = &quot;/&quot;;<br>        return NextResponse.redirect(url);<br>    }<br><br>    if (!token &amp;&amp; PRIVATE_ROUTES.some((path) =&gt; pathname.startsWith(path))) {<br>        url.pathname = &quot;/login&quot;;<br>        return NextResponse.redirect(url);<br>    }<br><br>    return NextResponse.next();<br>}<br><br>export const config = {<br>    matcher: [&quot;/((?!.+\\.[\\w]+$|_next).*)&quot;, &quot;/&quot;, &quot;/(api|trpc)(.*)&quot;]<br>};</pre><p>And that’s it!</p><p>I’m not sure if you find this easy, but I struggled with it when I was first learning.</p><p>This approach works with many other meta framework, not just Nextjs. There will just be some differences depending on the framework itself.</p><p>There may be debate on whether this topic is important, but when I faced this problem, I found no resources discussing it. So I decided to write this post, hoping that someone struggling as I did finds it helpful.</p><p>If you made it to the end, thank you for reading. I hope you face no bugs for the rest of the week!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=262fc2748158" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>