ionic-team / ionic-plugin-deeplinks

Handle deeplinks into your Ionic/Cordova apps from Universal Links, App Links, and Custom URL schemes. For those using Ionic 2, there are some nice goodies that make life easier.
Other
332 stars 220 forks source link

OAuth authorize callback deeplink only triggered once on Android and iOS #135

Open nowrap opened 6 years ago

nowrap commented 6 years ago

Hello, i am trying to implement an oauth process with ionic 3 on Windows 10 / Mac OS High Sierra.

Issue

On Android an iOS the me.deeplinks.route()-section is only triggered once. But on both platform i always get an: console.log: On deep link [object Object]

On Android it strangly also triggers the handleOpenURL().

Code (app.module.ts)

      if (window["cordova"] && window["cordova"].platformId !== 'browser') {

        me.deeplinks.route({
        }).subscribe((match) => {
          console.log("app::deeplinks:match", JSON.stringify(match));
          if (me.coachoauth.showAlerts) alert("deeplinks: " + JSON.stringify(match));

          if (match.$link) {
            me.coachoauth.handleCallback(match.$link.url);
          } else {
            if (me.coachoauth.showAlerts) alert("deeplinks failure: " + JSON.stringify(match));
          }
        }, (nomatch) => {
          console.log("app::deeplinks:nomatch", JSON.stringify(nomatch));
          if (me.coachoauth.showAlerts) alert("deeplinks: " + JSON.stringify(nomatch));

          if (nomatch.$link) {
            me.coachoauth.handleCallback(nomatch.$link.url);
          } else {
            if (me.coachoauth.showAlerts) alert("deeplinks failure: " + JSON.stringify(nomatch));
          }
        });
      }

      /**/(<any>window).handleOpenURL = (url) => {
        console.log("app::handleOpenURL:url", JSON.stringify(url));
        if (me.coachoauth.showAlerts) alert("handleOpenURL: " + JSON.stringify(url));
        //me.coachoauth.handleCallback(url);
      };/**/

Setup / Settings

This is my ionic info:

cli packages: (C:\Users\nowrap\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.2
    Cordova Platforms  : android 6.4.0 ios 4.5.3
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.9.1
    npm  : 5.5.1
    OS   : Windows 10

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

I adapted the auth0 discussion: https://github.com/auth0/auth0-cordova/issues/42

So I added to the config.xml: <preference name="AndroidLaunchMode" value="singleInstance" /> <plugin name="cordova-plugin-background-mode" spec="git+https://github.com/katzer/cordova-plugin-background-mode.git" />

The background-mode is for iOS. It is just added and not activated.

With the WKWebView Plugin the iOS-App crashes, so i am not using it right now: https://github.com/katzer/cordova-plugin-background-mode/issues/317

alex-steinberg commented 5 years ago

Use the global deeplinks module.


import ...

declare const IonicDeeplink: any; // so that there's no Typescript error

@Component()
export class MyClass {
  IonicDeeplink.route(
    {
      '/some-route': SomePage
    },
    match => { // do something },
    nomatch => console.log('deeplink error: ', JSON.stringify(nomatch));
  );
}