-
Notifications
You must be signed in to change notification settings - Fork 174
Description
Hi!
Thank you for sharing such a detailed and scalable architecture with video tutorials and source code.
I am unsure why inspite of replicating almost the entire codebase on my project, I am getting a "Error: The edge runtime does not support Node.js 'net' module." error. I tried removing sentry and refactoring all code to work without sentry but i still am unable to understand what the issue is.
I made edits to the middleware file to restrict access to /dashboard which I intend to make an authenticated path. However, the authenticationService throws the above mentioned error and it just does not work.
I am using ioctopus, drizzle-orm, lucia for auth and no other fancy packages. Would really appreciate your help in debugging this.
Here is my middleware code -
import { NextResponse, type NextRequest } from 'next/server';
import { getInjection } from '@/di/container';
import { AUTHENTICATION_SERVICE, SESSION_COOKIE } from '@/config';
import { authRoutes, publicRoutes } from "@/routes";
export async function middleware(request: NextRequest) {
// Check if the request is for an authentication route
const requestURL = new URL(request.url);
const isPublicRoute = publicRoutes.includes(requestURL.pathname);
if (!isPublicRoute) {
const sessionId = request.cookies.get(SESSION_COOKIE)?.value;
console.log(Request URL: ${new URL(request.url).pathname});
if (sessionId === undefined || sessionId === '') {
console.log(Session ID not found);
return NextResponse.redirect(new URL('/sign-in', request.url));
}
try {
const authenticationService = await getInjection(AUTHENTICATION_SERVICE);
await authenticationService.validateSession(sessionId);
console.log('Session is valid');
} catch (err) {
console.log(err);
return NextResponse.redirect(new URL('/sign-in', request.url));
}
}
return NextResponse.next();
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
/
'/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).)',
],
};
Here is my console output -
GET /sign-in 200 in 32ms
Request URL: /dashboard
Validating session with ID: dw6xiuadowx7iusizt35axw2coz5bvwoo6vqgjaq
Error: The edge runtime does not support Node.js 'net' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime {
}