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

Adding onSuccess callback to Accounts.ui.config #479

Closed
wants to merge 1 commit into from
Closed

Adding onSuccess callback to Accounts.ui.config #479

wants to merge 1 commit into from

Conversation

TimHeckel
Copy link

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!

@avital
Copy link
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 avital closed this Nov 15, 2012
@TimHeckel
Copy link
Author

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

@johndevor
Copy link

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).

@belisarius222
Copy link

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.

@johndevor
Copy link

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

@belisarius222
Copy link

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

@johndevor
Copy link

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)

StorytellerCZ pushed a commit that referenced this pull request Sep 18, 2021
…5-6.24.1

Update babel-preset-es2015 to version 6.24.1 🚀
StorytellerCZ pushed a commit that referenced this pull request Oct 1, 2021
I removed an if which I believe was redundant. In case it was really necessary, and I missed it, then I would suggest to add a comment with explanation for it's existence.

Also, I'm not sure what (if any) exceptions can be thrown by `this.added(...)`, but perhaps it would be a better idea to move `publishedKeys[doc._id]=true` after the `this.added(...)`?
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

Successfully merging this pull request may close these issues.

None yet

4 participants