I'm using firebase and am trying to implement a protected route system. Here's my code:
// ./middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { auth } from "@lib/firebase";
export async function middleware(req: NextRequest) {
const res = NextResponse.next();
if (!auth.currentUser && req.nextUrl.pathname.includes("/(protected)")) {
console.log("redirect");
return NextResponse.redirect(new URL('/', req.url));
}
return res;
}
The following error is thrown:
ChunkLoadError: Loading chunk app/(protected)/matching/page failed.
(missing: http://localhost:3000/_next/static/chunks/app/(protected)/matching/page.js)
Apologies if I'm missing something right in front of me. I appreciate any help!