Usage
To use the auth middleware, just create a file namedmiddleware.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.
Routes Matcher
Often, you may want to use path parameters or wildcard to match multiple routes. Here is an example of matchers that you can use.Wildcard
You can use(.*) to match all routes under a specific path.
Examples:
"/(.*)": Matches all routes under the root path."/public/(.*)": Matches all routes under the/publicpath./something/:user*: Matches all routes under the/something/:user(e.g./something/john,/something/john/doe, etc).
Path parameters
You can use the:param notation to match a path parameter with a given name.
Examples:
"/categories/:category": Matches all routes under the/categoriespath with a path parametercategory."/categories/:category/posts/:post": Matches all routes under the/categoriespath with two path parameterscategoryandpost.
Path named parameters must use “word characters” ([A-Za-z0-9_]) and start with a colon
:Advanced path parameters
You can use more advanced patterns to match path parameters with specific format. Examples:/something/:user*: Matches all routes under the/something/:user(e.g./something/john,/something/john/doe, etc)./something/(\\d+): Matches all routes under the/somethingpath with a path parameter that must be a number./something/:number-(\\d+): Matches all routes under the/somethingpath with a path parameter that must be a number and start withnumber-./something/(public|p): Matches all routes under the/somethingpath with a path parameter that must be eitherpublicorp.