I'm looking to use a conditional in the NextJS middleware.ts and I'm using an env variable to decide which parts of the matcher field will be. Either ["/folder/(.*)"] or ["/no-match"].
From what I understand, this is valid JavaScript since I get the expected result testing in an isolated page.
export { default } from "next-auth/middleware"
export const config = {
matcher:
process.env.NEXT_PUBLIC_AUTH_USERS === "true"
? ["/folder/(.*)"]
: ["/no-match"],
}
NOTE: "true" because boolean env args are strings.
I get an error:
Unsupported node type "ConditionalExpression" at "config.matcher".
The default config will be used instead.
Read More - https://nextjs.org/docs/messages/invalid-page-config
It says conditionals not allowed so is there another way I can use this logic?
Change to one of the options works fine.