NuxtN
Nuxt2y ago
1 reply
Artist201

Protecting Dynamic routs through Server middleware ?

Is there anyway to protect dynamic routs using server middle ware ?
I was using the following:
function isRouteProtected(incomingRoute : any, protectedRouts:any) {
  for (const protectedRoute of protectedRouts) {
    if (incomingRoute.startsWith(protectedRoute)) {
      // exception routs 
      if (incomingRoute.startsWith(exceptionRouts)) {
        continue 
      }
      return true; // Incoming route starts with a protected route
    }
  }
  return false; // No match found
}

which was doing fine for my case but i needed to change the routing and now i have a dynamic routes like this
/something/something/[slug]/something

sooo, how am i going to tell the middle ware to protect this rout ?
I really don't want to add a "protected" method at the start of each rout....
Was this page helpful?