middleware.ts
in the src
directory of your project and add the following code:
publicRoutes
array will be accessible without authentication.
If an unauthenticated user tries to access a protected route, they will be redirected to the login page on your Customer Portal.
(.*)
to match all routes under a specific path.
Examples:
"/(.*)"
: Matches all routes under the root path."/public/(.*)"
: Matches all routes under the /public
path./something/:user*
: Matches all routes under the /something/:user
(e.g. /something/john
, /something/john/doe
, etc).:param
notation to match a path parameter with a given name.
Examples:
"/categories/:category"
: Matches all routes under the /categories
path with a path parameter category
."/categories/:category/posts/:post"
: Matches all routes under the /categories
path with two path parameters category
and post
.:
/something/:user*
: Matches all routes under the /something/:user
(e.g. /something/john
, /something/john/doe
, etc)./something/(\\d+)
: Matches all routes under the /something
path with a path parameter that must be a number./something/:number-(\\d+)
: Matches all routes under the /something
path with a path parameter that must be a number and start with number-
./something/(public|p)
: Matches all routes under the /something
path with a path parameter that must be either public
or p
.