BUGFIX: Show relogin dialog when remote action results in redirect to login page #3327
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.
solves: #3320
The Problem
When the user is not authenticated, a remote action like "publish" answers with a
303
Redirect. ThefetchWithErrorHandling
mechanism on the client side however expects a401
response (which is a reasonable expectation, semantically speaking).The Solution
At first I thought it'd be best to make the UI API respond with correct status codes, but then I figured that the
303
redirect is actually more desirable in case someone hits the URL directly in the browser.So I adjusted
fetchWithErrorHandling
, so that it detects a redirect to the login page and enters the relogin-dialog routine as usual.The way this works is by looking into the fetch response: If it has been redirected and the target URL ends in
"login"
,fetchWithErrorHandling
assumes that this has been a redirect to the Neos login page. This is not quite safe, because in theory the redirect could have been configured differently. But I'm out of ideas as to how a more correct detection mechanism should look like in this case, and as a bugfix this should suffice to fix the problem for >99% of all setups.