N
Nuxt7mo ago
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
}
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....
1 Reply
Artist201
Artist2017mo ago
i just made it extract the field and put some word in place...
Want results from more Discord servers?
Add your server