Closed luke- closed 1 year ago
Open question is: What happens if the HumHub installation under the saved URL is no longer accessible and the user can not log out. how does he get back to the dialog?
@PrimozRatej I have seen that there are Javascript channels in Flutter to realise a communication with the WebApp and the Flutter App.
One goal would be to no longer display the "Opener" dialogue after a successful login. It should only appear again after a logout in the WebApp.
Would it be possible for me to use HumHub, e.g.
<script>
window.FLUTTER_CHANNEL_NAME.postMessage('humhub.login');
</script>
Or:
<script>
window.FLUTTER_CHANNEL_NAME.postMessage('humhub.logout');
</script>
The behaviour on the Flutter side should be that as soon as humhub.login
is received via the channel, the current URL of the opener is permanently saved and the opener is no longer displayed even after an app restart.
The behaviour on the Flutter side should be that as soon as humhub.login
is received via the channel, the current URL of the opener is "locked" and the opener is no longer displayed even after an app restart.
If the message humhub.logout
is received, the URL "lock" is removed and the opener is displayed directly.
It would be nice if the URL remained preset even after a logout.
Q: When the user goes back, the opener dialog should no longer appear. Even after reopening the app, the previous entered URL should be opened directly in the WebAppView.
Q: If the WebView HTTP Response contains the header 'X-HumHub-Logout', the entered URL should be deleted and the Opener dialog should be displayed again. If this is not reliably possible with headers, a solution via Javascript Channel or similar would also be an option.
The SafeStorage feature of the app can handle redirections and logins. When a user successfully redirects or logs in, the app saves the URL to its internal storage. Every time the user opens the app, the stored URL is read. The issue is that the WebView has limited capabilities when it comes to working with headers. Even setting headers seems to be a problem.
A possible workaround would be to create a wrapper that makes a request using something similar to "var html = Get(url, headers).html" and then loading the HTML string using the loadHtmlString method. However, I smell trouble here. An alternative suggestion would be to work with cookies or JavaScript channels. I have had experience working with channels in the past, and they have been effective.
Example of how we pass data from WebView to Flutter app for credit card token.
Lets say if you would want to send something back to WebView you can always run .js
Q: Open question is: What happens if the HumHub installation under the saved URL is no longer accessible and the user can not log out. how does he get back to the dialog? Since we are already checking the manifest.json file and only navigating to the HumHub installation if it exists, it should not be a problem. In case we receive a 404 response, we can redirect the user to an opener dialog where they can input a valid URL again.
If there is no other way than working with headers, I can check the new plugin flutter_inappwebview it seems that it has more in-depth and advanced functionalities.
@PrimozRatej Please see my reply regarding headers here: https://github.com/luke-/app/issues/17
@PrimozRatej Ok, then let's use Javascript Channels to Hide/Show the Opener Dialog.
Can you then provide me Javascript Code which I can use to hide
and show
the Opener dialoge.
I'll then add this to your test HumHub installation for testing.
@PrimozRatej Ok, then we'll use:
After a successful login, we trigger to hide the Opener permantly:
<script>
if (window.flutterChannel) {
window.flutterChannel.postMessage('humhub.mobile.hideOpener');
}
</script>
After a logout, we trigger this to show the Opener instantly:
<script>
if (window.flutterChannel) {
window.flutterChannel.postMessage('humhub.mobile.showOpener');
}
</script>
When a user enters a URL, we set the HumHub prop hideOpener
to true
if the corresponding manifest exists. The parsed manifest is saved in local storage so that if the user reopens the app and the data is present, they will be redirected directly to the selected instance. If the JS channel flutterChannel
with data humhub.mobile.showOpener
is detected, local storage is cleared and the user is redirected to the Opener dialog.
@PrimozRatej Thanks.
I would prefer that hideOpener
is also triggered by the Javascript Channel like the showOpener
. That way we can only do this after a successful login.
The check of the URL with the manifest shouldstill take place.
Thanks!
Of course, the value isHideDialog
is always affected by the JS Channel,
So if I trigger the msg. 'humhub.mobile.hideOpener' the dialog will not be displayed when the user goes back. Only in the case if the installation does not exist anymore or the user has cleared the local storage where the data for an instance was saved. (clear cache).
@PrimozRatej To prevent the user from having to clear the LocalCache manually if the installation has been deleted or moved, we can implement the following:
Every time the app is started, the "manifest.json" is read first and the validity of the installation is checked. If this is not the case, the opener is displayed. (In other words, HideOpener is reset). However, it would be good here if the last URL is still in the field.
It works exactly as you described. The Redirector
class implements the redirect functionality. The method ref.read(humHubProvider).getInstance()
retrieves the previously executed instance of HumHub
. This instance contains an action
method to verify the installation's validity. Regarding the "the URL is still in the field", I will create an issue for that feature.
Okay, thanks. That sounds good. Then I'll close the issue here.
@PrimozRatej FYI: On sometestproject12345
now automatically on Login hideOpener
and on Logout showOpener
is triggered. It works quite well!
When the user goes back, the opener dialog should no longer appear. Even after reopening the app, the previous entered URL should be opened directly in the WebAppView.
If the WebView HTTP Response contains the header 'X-HumHub-Logout', the entered URL should be deleted and the Opener dialog should be displayed again. If this is not reliably possible with headers, a solution via Javascript Channel or similar would also be an option.