andreaselia
andreaselia
CCConvex Community
Created by andreaselia on 8/20/2024 in #support-community
Next.js URL not changing using the documented middleware and ConvexAuth setup
When signing in using password auth, the page changes as expected, but the URL remains the same. Using the documented Convex Auth password setup, when I go to /sign-in and actually sign-in, the tasks page loads, but the URL remains as /sign-in until I refresh. Not sure if this is a bug or user error and I've missed something. Root layout:
<ConvexAuthNextjsServerProvider>
<html lang="en">
<body className={inter.className}>
<ConvexClientProvider>{children}</ConvexClientProvider>
</body>
</html>
</ConvexAuthNextjsServerProvider>
<ConvexAuthNextjsServerProvider>
<html lang="en">
<body className={inter.className}>
<ConvexClientProvider>{children}</ConvexClientProvider>
</body>
</html>
</ConvexAuthNextjsServerProvider>
Middleware:
const isSignInPage = createRouteMatcher(["/sign-in"]);
const isProtectedRoute = createRouteMatcher(["/tasks(.*)"]);

export default convexAuthNextjsMiddleware((request) => {
if (isSignInPage(request) && isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/tasks");
}

if (isProtectedRoute(request) && !isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/sign-in");
}
});
const isSignInPage = createRouteMatcher(["/sign-in"]);
const isProtectedRoute = createRouteMatcher(["/tasks(.*)"]);

export default convexAuthNextjsMiddleware((request) => {
if (isSignInPage(request) && isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/tasks");
}

if (isProtectedRoute(request) && !isAuthenticatedNextjs()) {
return nextjsMiddlewareRedirect(request, "/sign-in");
}
});
23 replies