1

My app working in local host. But when I deploy it on vercel it fires an error.

enter image description here

I fixed all errors. I use typescript in my project. Here also my _middleware.tsx file

import { getToken } from "next-auth/jwt";
import { NextResponse } from "next/server";

/** @param {import("next/server").NextRequest} req */
export async function middleware(req) {
  if (req.nextUrl.pathname === "/middleware-protected") {
    const session = await getToken({
      req,
      secret: process.env.SECRET,
      secureCookie:
        process.env.NEXTAUTH_URL?.startsWith("https://") ??
        !!process.env.VERCEL_URL,
    });
    // You could also check for any property on the session object,
    // like role === "admin" or name === "John Doe", etc.
    if (!session) return NextResponse.redirect("/api/auth/signin");
    // If user is authenticated, continue.
  }
}


I read the documentation and I searched in here but couldn't find any solution

sayinmehmet47
  • 490
  • 5
  • 21
  • 1
    That's just a warning because you're using a `_middleware` file, it's not what's causing the build to fail. Check the error message below it: _"> Build optimization failed: found page without a React Component as default export in `pages/fetchRequest`"_. Does this answer your question: [Can't build React/Next project - found page without a React Component as default export](https://stackoverflow.com/a/65598867/1870780)? – juliomalves Jan 08 '22 at 00:02

0 Answers0