Accounts-core with client-side router in (non)hash mode

Hi,

I was struggling now with implementing own UI for the accounts package with Vue - vue router. I had pretty rough time with those * Accounts.on…* methods like Accounts.onResetPasswordLink.

The reason was, that I use Vue-router in ‘history’ mode (but it would be the same issue with other routers for sure) and the AccountsClients seems to be dependent on using the hashes in the URL.

If I register route like /reset-password/:token the router matches it when calling http://www.myapp.com/reset-password/h_aS_h123 and mounts an UI component.

If I call a route like http://www.myapp.com/#/reset-password/h_aS_h123 the registered method kicks in but the path is not matched by the router.

I found the reason after looking in the meteor/packages/accounts-base/accounts_client.js In the attemptToMatchHash method if no hash is found in the URL return is being called -(omitting the done() callback completely)

I could work around this by not-implementing those Accounts.on… method and doing

// disable auto-login
Accounts._autoLoginEnabled = false;
Accounts.resetPassword( .... , (err) => {
    ....
    // enable auotlogin again
   Accounts._enableAutoLogin();
})

which is what is done internally by AccountsClients (defaultSuccessHandler === the done method )

But for me it seems, that accounts rely on using hashes in the URL and if you use some client-side router in other ‘mode’, than you will have to work around it. Moreover - this is not documented and totally confusing (I myself had to dive in to the code)

FYI This issue can be fixed by configuring Accounts on the server in Meteor.startup, with a couple lines…

  Accounts.urls.resetPassword = function(token) {
    return Meteor.absoluteUrl('reset-password/' + token);
  };
  Accounts.urls.enrollAccount = function(token) {
    return Meteor.absoluteUrl('enroll-account/' + token);
  };