Adding onSuccess callback to Accounts.ui.config #479

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants

I wanted to leverage the {{loginButtons}} handlebars helper method to create the account management widget, but that left me with little low-level control over the callback specified in one of the Meteor.loginWithXXX methods.

So I amended the Accounts.ui.config to accept an onSuccess callback. I'm sure my impl is not ideal, as this is my first PR for meteor. I'm happy to adjust this if need be.

What this enables me to do from the client is this:

Accounts.ui.config({
    onSuccess: function () {
        //perform addl authorization on Meteor.user() here
    }
});

Keep up the great work!

Contributor

avital commented Nov 15, 2012

You could achieve this with the following:

Meteor.autorun(function () {
  if (Meteor.userId()) {
    // on login
  } else {
    // on logout
  }
});

Closing this, but definitely re-open it if this doesn't resolve your issue.

avital closed this Nov 15, 2012

Totally agree. Should have asked about that before doing the work. Thanks!

This works nicely, but not when I don't want it to run when the user refreshes the page. Meteor treats each manual refresh as the user logging into the site, and triggers this code each time. Is there any elegant solution to not having this run on each refresh (only on the initial login)?

In my case, I use this code to redirect the user to /home/ after they login from the root url ('/'). It fails, however, when I try to manually load the root url, as it again redirects to /home/, thinking I'm logging in again (which I suppose I technically am).

Here's some code that Chris Mather and I figured out that will check whether Meteor will try to log in when the page first loads (not tested thoroughly for cross-browser compatibility):

var willTryToLogin = function() {
  return !! (window.localStorage && window.localStorage['Meteor.userId']);
};

I added this function into my routing filter chain, and now it doesn't redirect if it's trying to log in, and just hasn't finished yet.

That helped, thanks. Still rather ungainly, and I wish there was a true callback!

true... I wrote a package called event-horizon that lets you fire events and add callbacks. There's an example of a login event in the readme.

https://github.com/belisarius222/meteor-event-horizon

Very cool, will check it out!

Sent from the future

On Mon, Apr 8, 2013 at 5:36 PM, Ted Blackman notifications@github.com
wrote:

true... I wrote a package called event-horizon that lets you fire events and add callbacks. There's an example of a login event in the readme.

https://github.com/belisarius222/meteor-event-horizon

Reply to this email directly or view it on GitHub:
#479 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment