I'm using the entry file at the root of my app as a data layer, for redirects depending on session, which I'm retrieving using getServerSession. If at a point no session exists, user should be redirected to /home. This is the error from vercel;
my / file;
also attached is my proxy.ts
import { NextRequest, NextResponse } from "next/server"; import { getToken } from "next-auth/jwt"; export async function proxy(req: NextRequest) { const token = await getToken({req: req as any}); if (!token || !token.role) { return NextResponse.redirect(new URL("/home", req.url)); } return NextResponse.next(); } export const config = { matcher: ["/"] } "use server"; import { authOptions } from "@vendora/auth"; import { getServerSession } from "next-auth"; import { redirect } from "next/navigation"; export async function Index() { const session = await getServerSession(authOptions); if (!session?.user.role) { redirect("/onboarding") } switch (session.user.role) { case "buyer": redirect(process.env.NEXT_PUBLIC_STORE_URL as string); case "seller": redirect(process.env.NEXT_PUBLIC_SELLER_URL as string); case "admin": redirect(process.env.NEXT_PUBLIC_ADMIN_URL as string); default: redirect("/home") } } Generating static pages (0/27) ... Generating static pages (6/27) Error occurred prerendering page "/home". Read more: https://nextjs.org/docs/messages/prerender-error TypeError: Cannot destructure property 'auth' of 'a' as it is undefined. at f (.next/server/chunks/711.js:17:51199) at p (.next/server/chunks/711.js:1:41685) at (.next/server/chunks/711.js:1:42254) at q (.next/server/chunks/711.js:1:42235) { digest: '3188648309' }
Export encountered an error on /home/page: /home, exiting the build. ⨯ Next.js build worker exited with code: 1 and signal: null ELIFECYCLE Command failed with exit code 1. Error: Command "pnpm run build" exited with 1