-
Notifications
You must be signed in to change notification settings - Fork 213
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
(feat) OA-41: openmrsFetch() should handle redirects #1231
Conversation
Size Change: -85.8 kB (-1.37%) Total Size: 6.16 MB
ℹ️ View Unchanged
|
This is a great addition @ibacher because it will also automatically address one of the requirements for https://openmrs.atlassian.net/browse/OA-37, i.e. redirect the user to the IDP upon logout when the oauth2 module sets the location header in the response, when do you intend to move this PR out of the draft state? |
Basically, once I'm able to test that it works as expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks, @ibacher!
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
This implements a simple protocol for the backend to be able to send redirect responses to the frontend.
Normally, redirect responses are handled by a HTTP response in the 300-399 range, with a
Location
header indicating where the page should redirect to. The problem is how this is handled withfetch()
requests. Specifically, while using thefetch()
API, 3xx responses cause the fetch request itself to redirect to the new URL, meaning that the user's UI doesn't change at all. For SPAs, this is usually the desired behaviour, since SPAs will usually do the work on the frontend.Instead, this hijacks the meaning of a 204 ("No Content") response from the backend. If the response is a 204 and there's a
Location
header and this feature hasn't been turned off via config, thenopenmrsFetch()
will redirect to the URL specified in the header. This gives us a small escape hatch so the backend can redirect the browser to a specific page.Screenshots
Related Issue
Other