DannyD
Convex Community8mo ago
4 replies
Danny

Convex Auth + Next.js headers error

Hiya, i'm trying to deploy a Next.js + Convex (auth), but am getting the error attached. It's definitely related to my middleware in some capacity. Here's my middleware file:
import {
  convexAuthNextjsMiddleware,
  createRouteMatcher,
  nextjsMiddlewareRedirect,
} from "@convex-dev/auth/nextjs/server";

const isSignInPage = createRouteMatcher(["/signin"]);

export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
  if (isSignInPage(request) && (await convexAuth.isAuthenticated())) {
    return nextjsMiddlewareRedirect(request, "/");
  }
  if (!(await convexAuth.isAuthenticated()) && !isSignInPage(request)) {
    return nextjsMiddlewareRedirect(request, "/signin");
  }
});

export const config = {
  // The following matcher runs middleware on all routes
  // except static assets.
  matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};


It also looks like a lot of other people are experiencing the same issue: https://github.com/get-convex/convex-auth/issues/120
DnjxoKJ.png
GitHub
The issue appears when using SSA in Next JS Runtime: Bun version 1.1.34 Package version: "convex": "^1.17.0" "@auth/core": "0.36.0" "@convex-dev/auth&qu...
Error: `headers` was called outside a request scope. · Issue #120 ...
Was this page helpful?