#NextResponse.redirect() throwing ChunkLoadError

5 messages · Page 1 of 1 (latest)

wide spade
#

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!

wintry dove
#

did you find something about that issue ?

wide spade
#

I fixed the error but firebase, in the way i am handling it, does not work server side, so this was a lost cause from the start

blazing river
#

You should use the admin SDK which works in server environment.

#

If I see this right, you are importing auth from lib/firebase. That should not work, you can only have access to auth and other services using the admin SDK which works only in server environment