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
Conversation
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. |
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. |
Very cool, will check it out! On Mon, Apr 8, 2013 at 5:36 PM, Ted Blackman notifications@github.com
|
…5-6.24.1 Update babel-preset-es2015 to version 6.24.1 🚀
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(...)`?
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 thecallback
specified in one of theMeteor.loginWithXXX
methods.So I amended the
Accounts.ui.config
to accept anonSuccess
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:
Keep up the great work!