While deploying - A Node.js API is used (process.exit at line: 1451) which is not supported in..
While deploying my next.js app on vercel it's giving this error
./node_modules/better-auth/dist/chunk-62MWLLEG.js
A Node.js API is used (process.exit at line: 1451) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime
9 Replies
better auth doesn't work on edge
How to resolve the issue? I am deploying in vercel with better-auth as authentication
most likely your either setting the runtime to edge in a route with
export const runtime = 'edge';
along with using better auth which doesnt work.
or your using better-auth in you middleware.ts
@joseph013318 Read up what the edge runtime is and also how nextjs middleware worksmost likely either a export const runtime = 'edge';Better Auth doesn't work on edge.
I know? Im saying that mostly likely the issue?
I missunderstood you, sorry.
@Ping @lonelyplanet Yes using it in middleware. This is the exact code I used as in the better-auth docs
https://www.better-auth.com/docs/integrations/next#middleware
I need protected routes with auth! How do I solve the issue?
Next.js integration | Better Auth
Integrate Better Auth with Next.js.
Care to share your middleware?
@lonelyplanet Sure.
import { getSessionCookie } from "better-auth/cookies";
import { NextResponse } from "next/server";
export async function middleware(request) {
const sessionCookie = getSessionCookie(request);
console.log("sessionCookie", sessionCookie);
// Optionally pass config as the second argument if cookie name or prefix is customized.
if (!sessionCookie) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/dashboard"],
};
Only in build time the error is occuring