Better Auth (auth.api.getSession) causes problem in edge runtime
Hey everyone, I am new to using Better Auth. I am using a middleware to call auth.api.getSession() to check if the user is authenticated:
• It grabs the current request headers (cookies, tokens, etc.).
• Passes them to auth library (likely better-auth or next-auth) to fetch the current session.
• If no session exists, it redirects the user to /sign-in.
• Otherwise, it allows the request to continue.
But I am getting the following error:
2025-05-20T20:02:11.555Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR Error: The edge runtime does not support Node.js 'perf_hooks' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime {
} ⨯ [Error [APIError]: Failed to get session] Stuck on this problem - is there any workaround?
} ⨯ [Error [APIError]: Failed to get session] Stuck on this problem - is there any workaround?


3 Replies
i dont think it is better auth tbh
it might be other libs you are using
plently of people use better auth in their next middleware
Hi! Thanks for the response, when I comment out:
const session = await auth.api.getSession({
headers: await headers(),
});
The problem goes away. (but obviously no session or cookies are saved ).
Hey! Check that: https://www.better-auth.com/docs/integrations/next#middleware