Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next(false) #108

Closed
FredericHeem opened this issue Aug 28, 2017 · 2 comments · Fixed by #131 · May be fixed by #86
Closed

next(false) #108

FredericHeem opened this issue Aug 28, 2017 · 2 comments · Fixed by #131 · May be fixed by #86

Comments

@FredericHeem
Copy link

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
Copy link
Author

Throwing an exception inside the action instead of calling next(false) makes my issue go away.

@frenzzy
Copy link
Member

frenzzy commented Aug 28, 2017

  • 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 than null or undefined to stop iteration.
const middlewareRoute = {
  path: '/admin',
  children: [/* ... */]
  action(context) {
    if (!userAuthorized) {
      return 'stop' // not null/undefined
    }
    return context.next()
  }
}

Demo: https://jsfiddle.net/frenzzy/2nq9o896/

@frenzzy frenzzy mentioned this issue Aug 28, 2017
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants