#UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme).

8 messages · Page 1 of 1 (latest)

sour flicker
#

I have used middleware.ts file in Next.js to persist login but I am getting there errors:

○ Compiling /src/middleware ...
 ⨯ node:stream
Module build failed: UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:stream
./node_modules/firebase-admin/node_modules/@fastify/busboy/lib/main.js
./node_modules/firebase-admin/lib/utils/api-request.js
./node_modules/firebase-admin/lib/auth/auth-api-request.js
./node_modules/firebase-admin/lib/auth/auth.js
./node_modules/firebase-admin/lib/auth/index.js
./node_modules/firebase-admin/lib/esm/auth/index.js

Here is my middleware.ts

import { NextRequest, NextResponse } from "next/server";
import { getAuth } from "firebase-admin/auth";

export async function middleware(req: NextRequest) {
  const sessionCookie = req.cookies.get("session")?.value;

  if (!sessionCookie) {
    return NextResponse.redirect(new URL("/login", req.url));
  }

  try {
    await getAuth().verifySessionCookie(sessionCookie, true);
    return NextResponse.next();
  } catch (error) {
    console.error("Failed to verify session cookie", error);
    // Redirect to login on failure
    return NextResponse.redirect(new URL("/login", req.url));
  }
}

// Apply middleware to specific routes
export const config = {
  matcher: ["/", "/admin"],
};
misty hamletBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

sour flicker
#

I am working with Next.js and Firebase and using Firebase auth. I have seen multiple approaches to persist login and I am not sure which one to use.
Please help out.

#

Currently, what I am doing is, when the user logs in, I set a cookie named session and then I have this middleware.

daring hazel
#

in nextjs, the runtime used to run middleware.ts is an "edge runtime" to make it run faster since it's called for every request. the edge runtime does not include the same APIs as node like the error you encountered: Reading from "node:stream" is not handled by plugins (Unhandled scheme)

sour flicker