Next.js Discord

Discord Forum

Middleware flooding requests?

Unanswered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
Hello, I am trying to setup a middleware for PocketBase authentication and I am running into a problem where I open the route I am trying to protect, in this case /profile, in the network tab I see it starts flooding requests as hell to the URL with this request: /profile?_rsc=384k2

If someone could explain what is happening or what I am doing wrong i'd highly appreciate it.

Here is my middleware.ts
And also a video of my network tab after opening /profile: https://streamable.com/ii5kak
import { NextResponse, NextRequest } from "next/server";
import PocketBase from "pocketbase";

const pb = new PocketBase(`${process.env.DB_HOST}:${process.env.DB_PORT}`);

export async function middleware(req: NextRequest) {
  pb.authStore.loadFromCookie(req?.headers?.get("cookie") || "");
  const isValid = pb.authStore.isValid;

  if (!isValid) {
    console.log("MIDDLEWARE: Invalid User");
    return NextResponse.redirect(new URL("/login", req.url));
  }
  console.log("MIDDLEWARE: Valid user");
}

export const config = {
  matcher: ["/profile"],
};

1 Reply

RhinelanderOP
Actually turns out the problem is related to turbopack, after removing --turbo from packages.json it stopped doing it.
  "scripts": {
    "dev": "next dev --turbo", // removed --turbo from here
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },