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

fix: handle new login endpoints [LIBS-600] #846

Merged
merged 13 commits into from
Apr 29, 2024

Conversation

tomzemp
Copy link
Member

@tomzemp tomzemp commented Apr 25, 2024

See https://dhis2.atlassian.net/browse/LIBS-600

Summary

This change fixes the app-platform login modal to:

  1. use new auth/login endpoints if v41 or greater
  2. use old struts login (/dhis-web-commons-security/login.action) if v40 or less

Detecting version

If a server is v41 or greater, api/loginConfig is accessible with the version. Therefore, this PR assumes that if a request to api/loginConfig succeeds that the server is v41+. This logic, obviously, has some limitations because the request could fail for other reasons (e.g. server is down), but this is not in general likely.

UI Improvements

General

I've disabled the log in button when login is in progress.

Normal apps

When using api/auth/logic, we have a REST api and will get a 400-range error back if authentication fails. This means that we can catch errors and display them back to the user. When using the struts endpoint, even successful authentication errors out. As a consequence, I've added error display if the server is detected as v41+ and have otherwise used the previous approach of refreshing the window (for v40 or less).

Note that you can successfully authenticate (regardless of version), and have CORS errors that are only detected on reload (note that this appears like the older version workflow: you authenticate, the app reloads, and then the cors error leads to the login modal to display again). I have not made any modifications to specifically catch CORS errors and display them.

v42:
login_modal_dev

v39:
login_modal_239dev

Login app

I have added some handling for the case where you are have a login app. Previously, running the login app required that you specify the DHIS2_BASE_URL environment variable. This adds a bit more refactoring to the code, but I think it's worth it as it makes login app development less finicky and also would be relevant if we introduce "public" app types in the future.

image

Code notes

I thought about doing a bit more a refactor (e.g. to get rid of need for page refreshing with v41+, but then I felt that was a bit complicated and not worth the effort at the moment).

@@ -23,6 +23,7 @@ const AppAdapter = ({
loginApp,
children,
}) => {
const [loginBaseUrl, setLoginBaseUrl] = useState(url)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass the base url (logic in ServerVersionProvider) to LoginAppWrapper in order to display the correct redirection for safe mode login.

The easiest option would be to just move the LoginAppWrapper component into ServerVersionProvider, but I thought maybe the current code structure was preferable in terms of displaying where the wrapper was? So hence this use of state variable to track the updates from ServerVersionProvider in this parent component.

Copy link
Member

@Birkbjo Birkbjo Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why can't we just read from the server-version context in LoginAppWrapper, since it's a child of that provider?
EDIT: Ah...nvm, that's not exposed from that provider.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Birkbjo : we can use useConfig within LoginAppWrapper to get the baseUrl. I didn't want to do that initially because I thought it was kind of confusing to use the hook from app-runtime there, but we're also using useConfig in the ConnectedHeaderBar component, so I guess using useConfig in this case would be more consistent. I think my hesitation was just that within the directory we have some components that have access to the context and some that do not, so you have to pay attention to where these components are in the hierarchy.

I've updated to use useConfig in LoginAppWrapper. 🙏

Copy link
Contributor

@KaiVandivier KaiVandivier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks great, I like the changes you added 😀

Added a few tips for your consideration 🙂

I tested it out on pre- and post-v41 changes, but didn't try out a login app

adapter/src/components/ServerVersionProvider.js Outdated Show resolved Hide resolved
adapter/src/index.js Outdated Show resolved Hide resolved
adapter/src/components/LoginModal.js Outdated Show resolved Hide resolved
adapter/src/components/LoginModal.js Outdated Show resolved Hide resolved
adapter/src/components/LoginModal.js Outdated Show resolved Hide resolved
@tomzemp tomzemp merged commit 4512825 into master Apr 29, 2024
6 checks passed
@tomzemp tomzemp deleted the LIBS-600/handle-new-login-endpoints branch April 29, 2024 13:00
dhis2-bot added a commit that referenced this pull request Apr 29, 2024
## [11.2.1](v11.2.0...v11.2.1) (2024-04-29)

### Bug Fixes

* handle new login endpoints [LIBS-600] ([#846](#846)) ([4512825](4512825))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 11.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

5 participants