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
Meteor.userId() throws an error in validateLoginAttempt/onLogin/onLoginFailure callbacks #4862
Comments
Changes to packages/callback-hook: - Add bindEnvironment option to Hook constructor (defaults to true). - Add internal helper function dontBindEnvironment() which does all the error handling stuff like Meteor.bindEnvironment() but doesn't change the environment. - Use dontBindEnvironment() instead of Meteor.bindEnvironment() when bindEnvironment option is false. - Add tests. Changes to packages/accounts-base: - Create hooks with { bindEnvironment: false } - Add test for whether Meteor.userId() is available in login callbacks.
It is, in fact, the Meteor.bindEnvironment() wrapping that is causing the problem. I've just created PR #4867 which fixes it. I don't see a good reason for using bindEnvironment here. Maybe @awwx just used because it was part of the Hook code that he extracted from livedata when he implemented login hooks 18 months ago? |
Changes to packages/callback-hook: - Add bindEnvironment option to Hook constructor (defaults to true). - Add internal helper function dontBindEnvironment() which does all the error handling stuff like Meteor.bindEnvironment() but doesn't change the environment. - Use dontBindEnvironment() instead of Meteor.bindEnvironment() when bindEnvironment option is false. - Add tests. Changes to packages/accounts-base: - Create hooks with { bindEnvironment: false } - Add test for whether Meteor.userId() is available in login callbacks.
Thanks for the PR! |
Thanks for the fast review and merge! On Tue, Aug 4, 2015 at 1:57 PM, Sashko Stubailo notifications@github.com
|
The brettle:workaround-issue-4862 package provides a workaround for Meteor releases where this is not fixed. |
Meteor.userId()
is throwing an error when called withinAccounts.validateLoginAttempt
/Accounts.onLogin
/Accounts.onLoginFailure
callbacks. This is preventing me from determining which (if any) already logged in user made the login attempt.Here's a reproduction recipe using this github repo:
Visit http://localhost:3000/ and click the "Login with correct password" button. You'll get this on the server console:
Click the "Login with incorrect password" button and you'll get this on the server console:
I suspect this is related to these API functions using Hooks which binds the callbacks "with
Meteor.bindEnvironment
, so they will be called with the Meteor environment of the calling code that registered the callback."The text was updated successfully, but these errors were encountered: