For SpartaF
Convex Community5mo ago
1 reply
For Sparta

Convex auth Nextjs Middleware not redirecting

import {
  convexAuthNextjsMiddleware,
  createRouteMatcher,
  nextjsMiddlewareRedirect,
} from "@convex-dev/auth/nextjs/server";
 
const isSignInPage = createRouteMatcher(["/signin"]);
const isProtectedRoute = createRouteMatcher(["/product(.*)"]);
 
export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
  if (isSignInPage(request) && (await convexAuth.isAuthenticated())) {
    return nextjsMiddlewareRedirect(request, "/product");
  }
  if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
    return nextjsMiddlewareRedirect(request, "/signin");
  }
});
 
export const config = {
  // The following matcher runs middleware on all routes
  // except static assets.
  matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};


Following the docs I am not seeing a redirect after signing in. The webhook response looks like it's getting the auth token. I have followed all the docs so not sure what's going on. convexAuth.isAuthenticated() never responds with true and when I log out the token in the middleware it's undefined.


NextJS version: 15.4.6
convex auth version: 0.0.88
@auth/core: 0.37.0
React version: 19.1.0
Was this page helpful?