Had a problem in "Adding Parameterized Routes to a Next.js App" where accessing the /chats/:chatid route, the login was not redirecting to the callbackUrl (it's not adding the callbackUrl to the path at all).
This was the solution I came up with:
import { NextResponse } from "next/server";
import { auth } from "@/auth";
export const config = {
matcher: ["/chats/:chatid*"],
};
export default auth((req) => {
if (!req.auth) {
const loginUrl = new URL("/api/auth/signin", req.url);
loginUrl.searchParams.set('callbackUrl', req.url);
return NextResponse.redirect(loginUrl);
}
});