auth0-ionic2-samples icon indicating copy to clipboard operation
auth0-ionic2-samples copied to clipboard

Lock not shown after logout

Open bujardeari opened this issue 7 years ago • 1 comments

When i hit the logout button, the user logs out, but when i try to login again, i would like the lock to be shown first , not to directly logg in with the last logged in user. When i manually go and clean history on Chrome (Android), and then try to login on my app again, then it shows up the lock. This may not be an issue, but maybe someone can help me how to achieve what i want?

bujardeari avatar Jun 08 '17 11:06 bujardeari

Hi @bujardeari ! I was suffering from the same. As we see, we got no replies from developers yet - unfortunately.

I had to go into Auth0Cordova sources to find an alternative.

I implemented a logout method in index.js.

The only thing it does is to call the browser/safarariwebview agent to redirect to Auth0 logout URL...

Something like:

CordovaAuth.prototype.logout = function (parameters, callback) {
  if (!callback || typeof callback !== 'function') {
    throw new Error('callback not specified or is not a function');
  }

  var self = this;

  getAgent(function (err, agent) {
    if (err) {
      return callback(err);
    }

    
    var returnTo = encodeURIComponent('YOUR_SCHEME://YOUR_SCHEME/cordova/YOUR_SCHEME/callback');
    agent.open('https://YOUR_DOMAIN.auth0.com/v2/logout?client_id=YOUR_CLIENT_ID&returnTo='+returnTo, function (error, result) {
      if (error != null) {
        session.clean();
        return callback(error);
      }

      if (result.event === 'closed' && getOS() === 'ios') {
        session.clean();
        return callback(new Error('user canceled'));
      }

      if (result.event !== 'loaded') {
        // Ignore any other events.
        return;
      }

      agent.close();

      callback(null,{status:'ok'})
    });
  });
};

It works on both Android an iOS.

In Android we still have a drawback. The agent.close() line don't actually make the chrome browser to close. I think there is a bug in SafariWebView (https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller) open for this w/o correction prevision. I'll dig it later.

gusmao avatar Jun 29 '17 12:06 gusmao