Closed NickTheTurtle closed 4 years ago
Hi @NickTheTurtle
Do you encounter any similar issues when logging in regularly? I'm still trying to reproduce the issue on my end.
Thanks!
Hi, thanks for the quick reply. Logging in normally does not give any weird behaviors. I found this blog online that documented the same error: https://medium.com/differential/react-native-meteor-auth-with-email-username-and-password-d2085c732276. Seems like the bug existed for quite some time.
One more thing to try, can you add a handler for the Accounts.onLoginFailure
event:
Accounts.onLoginFailure(err => {
console.error(err);
});
I tried Accounts.onLoginFailure, and the error it logged was… "undefined", curiously. I attached the image below:
Currently, onLoginFailure
doesn't actually tell you the error, just calls the callback when there is one. However, this points to an error in the createUser call. Are you calling createUser with a callback?
Accounts.createUser({...}, err => {
if(err) console.error(err);
});
The callback should have an error since onLoginFailure is being called. That should give you some more info.
I can verify that a user is indeed created by checking with "meteor mongo". Also, the error callback in createUser is not called as I set it to display pop up boxes if errors occurred (and the pop up boxes do appear when, say the email has already been associated with another account).
Thats really strange. When createUser is called, whatever error/result it receives is passed directly to _handleLoginCallback
which in turn triggers onLoginFailure
if there was an error, but the same error should have been passed to your callback.
If you would be willing to make some changes to your local version of the package, you can make a change to:
node_modules/@meteorrn/core/src/user/Accounts.js
Inside the createUser
method, you can log the error and result received to confirm that there is no error and that a token is being returned.
If you'd prefer not to make these changes, I have a release planned for tomorrow that implements some deeper debugging.
Ok, so after putting some console messages in Accounts.js, I found out that every function that's supposed to be called is called, and err was always undefined. However, after making the changes to Accounts.js, the app reloaded on the second time and the user got logged in. This did not happen when changing my ReactNative files, curiously. This makes me think that the app did successfully log the user in after account creation, but the notification did not get propagated and Meteor.user() did not change.
Could you try adding a timeout and logging Meteor.user()
and Meteor._userIdSaved
(note that _userIdSaved is a string value not a function)? Once the login callback is handled, _userIdSaved
is immediately set, but its possible that for some reason the user object isn't being received from the server.
It logs null
and undefined
, respectively.
So, when _handleLoginCallback
is called _userIdSaved should be immediately set (unless there is an err). When you put your console messages, did you confirm that _handleLoginCallback was not receiving an err object? If so, something else is happening, possibly related to your other issue (how the functions are being bound to this
).
Yeah, no error occurred. Also, I have a logging in indicator that fires when the user is logging in but doesn't upon account creation. I was able to verify that Users._startLoggingIn was called though. If I manually call Meteor._startLoggingIn, the logging in indicator works.
Next, instead of calling Accounts.createUser, I did this:
Meteor._startLoggingIn();
Meteor.call(
'createUser',
{
email: this.state.email,
password: this.state.password,
},
(error, result) => {
Meteor._endLoggingIn();
Meteor._handleLoginCallback(error, result);
if (error) {
//handle error
}
},
);
and it now works as expected. Strange.
A reproduction of this and #20 might be helpful if possible.
Hey @NickTheTurtle, any chance this issue could be related to #21, where this wasn't being bound correctly?
Hi @NickTheTurtle, just following up to see if this issue is resolved?
I don't think it's a "this" issue since I'm calling Accounts.createUser in a class method.
Hi @NickTheTurtle, could you see if the issue is still happening with release 2.0.13
?
Hi @NickTheTurtle, any updates on this?
Closing this as it is stale. Feel free to re open if the issue persists.
Describe the bug Either Accounts.createUser does not immediately log user in, or Meteor.user() and Meteor.userId() does not get updated automatically when Accounts.createUser is successful
To Reproduce Steps to reproduce the behavior:
App.js code:
Accounts.createUser code:
I can verify that a new user is indeed created in the database. However, upon successful creation of user, app does not automatically switch to but stays on .
Expected behavior Upon successful creation of user, app does automatically switch to .
Screenshots N/A
Device (please complete the following information):