Next.js Discord

Discord Forum

Middlware Error

Answered
Arinji posted this in #help-forum
Open in Discord
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { validateBetaJWT, validateJWT } from "@/lib/modifyJWT";

export async function middleware(request: NextRequest) {
  const betaToken = request.cookies.get("beta_token")?.value;
  const token = request.cookies.get("token")?.value;
  if (request.nextUrl.pathname.startsWith("/beta")) return;

  let isBeta = await validateBetaJWT(
    betaToken,
    request.headers.get("x-forwarded-for")
  );
  if (isBeta === undefined) isBeta = false;

  console.log(isBeta);
  if (!isBeta) return NextResponse.redirect(`${process.env.WEB_DOMAIN}/beta`);

  if (request.nextUrl.pathname.startsWith("/dash")) {
    if (!token || !(await validateJWT(token))) {
      const nextPath = encodeURIComponent(request.nextUrl.pathname);
      return NextResponse.redirect(
        `${process.env.WEB_DOMAIN}/login?next=${nextPath}`
      );
    }
  }
}

Hi so the isBeta if statement is causing the page to like loose its tailwind for some reason?
First picture is the line removed, and second picture is with the line
Also the console statement returns false.
Answered by DirtyCajunRice | AppDir
you need to return something
View full answer

3 Replies

you never return nothing
its a middleware
you need to return something
Answer