next(false)
FredericHeem opened this issue · 2 comments
FredericHeem commented
Is there a way to stop any middleware by calling next(false)
?
Right now, calling next(false)
will result in a Page Not Found
exception, would it be possible to throw another kind of exception (Redirect ?)
This is a situation which occurs when redirecting to a login page when the user is not authenticated.
Let me know your thought.
FredericHeem commented
Throwing an exception inside the action instead of calling next(false)
makes my issue go away.
frenzzy commented
context.next()
iterates through children routes and returns result or null.context.next(true)
iterates through remaining routes and returns result or throws an exception.return
anything other thannull
orundefined
to stop iteration.
const middlewareRoute = {
path: '/admin',
children: [/* ... */]
action(context) {
if (!userAuthorized) {
return 'stop' // not null/undefined
}
return context.next()
}
}