Redirect only when auth is required #155
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update: for hapi 17 support, see PR #186
Fixes #154.
Q: What's the purpose of
redirectTo
?A: Redirecting preempts the original route handler to protect it from unauthenticated requests.
Q: But what about routes that explicitly want to process unauthenticated requests? Isn't this the purpose of
optional
andtry
modes?A:
redirectTo
screws them up. Oops.Okay, so ... let's fix this and respect the auth mode.
This changes two closely related things. First and most importantly, it changes the behavior of
redirectTo
so that its effects only apply to auth moderequired
. Thus it no longer conflicts with the intent ofoptional
andtry
modes. Secondly, it removesredirectOnTry
.I removed
redirectOnTry
because:try
. I think everyone who is usingtry
just set this tofalse
, which is redundant now given the new behavior ofredirectTo
.redirectTo
makes this semver major anyway. Now is a good time to remove it so that migration is easier and more intuitive.The diff for the tests is poor. Basically just added a test for
optional
auth mode, fixed the one fortry
, and removed the obsoleteredirectOnTry
test. Also fixeduri
->url
(see this) and the weird executables while I was here. Happy to split things up if necessary.