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

Issue when using InAppBrowser in combination with Android Back button #7

Open
torsorensen opened this issue Jul 5, 2018 · 1 comment

Comments

@torsorensen
Copy link

torsorensen commented Jul 5, 2018

Hi there,

My Setup
I'm running your project on my physical Android device with my own keycloak server.
I've also installed the officially supported Ionic InAppBrowser plugin in order for the user to perform the login "inside my app".

Issue 1, not resolved
When my app loads, it immediately sends me to the keycloak served login page as dictated by the main.ts file.

So far so good. If I don't login but rather use the back button of the Android device, I'm experiencing an issue. It closes the InAppBrowser, and shows no signs of my application except for the tag of the page. I know, because if I change the body's background colour to red using CSS, I see a red page.

I think it's safe to assume that some Android users will click the back button while viewing the Keycloak login page. At the moment, I don't know how to "fix" this, as I cannot find a way to listen for the "close" event of the InAppBrowser. Any help would be appreciated!!

Issue 2, which I can fix
If I then press the back button AGAIN, the app goes to the background (not force-killed). Then, when the app is re-opened, the InAppBrowser is not ready, and the default OS browser opens, so the user doesn't experience opening my app.
I've came around this issue by putting your KeycloakService.init call inside a deviceready callback (main.ts file still):

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log("onDeviceReady");
    initAppWithKeycloak(); //calls the block of code containing the KeycloakService.init() and the Promise callbacks
}
@torsorensen
Copy link
Author

I managed to get a bit further by not modifying the main.ts as this repo suggests.
In general, we should NOT modify this file. See Ionic Team mharington's answer here https://forum.ionicframework.com/t/solved-build-app-prod-release-error/79631/2

As an alternative, and I believe, in the correct way, I'm now initialising Keycloak after the platform.ready event, as exemplified here:
https://github.com/sergeyrolich/ionic2-keycloak/blob/master/src/app/app.component.ts

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

No branches or pull requests

1 participant