DemocracyEarth / wallet

Censorship resistant democracies.
https://democracy.earth
MIT License
1.5k stars 286 forks source link

User registration fails sometimes #292

Open vjrj opened 6 years ago

vjrj commented 6 years ago

This is a Bug Report

:tophat: User registration fails sometimes

For bug reports:

fails with this error:

TypeError: Cannot read property \'username\' of undefined\n    at Subscription._handler (imports/api/server/publications.js:116:40)

To register as a user correctly

The common testing configuration.

vjrj commented 6 years ago

I see that if (Meteor.user()) is used in server side publications.

I use prefer to use if (this.userId) instead. Some link: https://stackoverflow.com/questions/16532316/how-to-get-meteor-user-to-return-on-the-server-side sample: https://github.com/comunes/todos-contra-el-fuego-web/blob/1360f742f3ba44c60fe3fa904a6450d57713f291/imports/api/Users/server/publications.js#L18

I think that method userCount in imports/api/server/methods.js fails also because of this.

vjrj commented 6 years ago

See also https://github.com/DemocracyEarth/sovereign/issues/267#issuecomment-380939793 for a similar userCount fail log.

vjrj commented 6 years ago

With other words, probably setting Meteor.user() to a const fix this:

const user = Meteor.user()
if (user) {

so we don't call Meteor.user() two times.

vjrj commented 6 years ago

A related error but in client side trying to sign-up:

TypeError: Cannot read property 'username' of undefined
  at _validateUsername(/app.js:19714:61)
  at Signup.handleBlur(/app.js:8755:33)
  at HTMLUnknownElement.boundFunc(/packages/modules.js:130200:9)
  at HTMLUnknownElement.wrapped(/packages/flowkey_raven.js:601:21)
  at Object.ReactErrorUtils.js.ReactErrorUtils.invokeGuardedCallback(/packages/modules.js:130206:16)
  at executeDispatch(/packages/modules.js:129987:21)
  at Object.executeDispatchesInOrder(/packages/modules.js:130010:5)
  at executeDispatchesAndRelease(/packages/modules.js:129404:22)
  at executeDispatchesAndReleaseTopLevel(/packages/modules.js:129415:10)
  at Array.forEach(<anonymous>)
  at forEachAccumulated(/packages/modules.js:130309:9)
  at Object.processEventQueue(/packages/modules.js:129615:7)
  at runEventQueueInBatch(/packages/modules.js:136665:18)
  at Object.handleTopLevel [as _handleTopLevel](/packages/modules.js:136675:5)
  at handleTopLevelImpl(/packages/modules.js:141650:24)
  at ReactDefaultBatchingStrategyTransaction.perform(/packages/modules.js:132677:20)
  at Object.batchedUpdates(/packages/modules.js:141565:26)
  at Object.batchedUpdates(/packages/modules.js:131365:27)
  at dispatchEvent(/packages/modules.js:141725:20)
  at HTMLDocument.wrapped(/packages/flowkey_raven.js:601:21)
  at Bc(<anonymous>:480:385)
  at Object.apply.navigator(<anonymous>:486:48)
  at apply.ELEMENT(<anonymous>:486:72)
  at callFunction(<anonymous>:361:33)
  at apply.ELEMENT(<anonymous>:371:23)

More detailed info (browser, etc): https://sentry.comunes.org/democracy-earth/ci-testing-results/issues/618/

virgile-dev commented 6 years ago

That some issue reporting right there ! @vjrj

vjrj commented 6 years ago

I think that this is already fixed

vjrj commented 6 years ago

Reopening: Still the same error but in other part of the code:

20180511-17:37:07.333(2)? Exception from sub feed id 6RtPuvG6qWAWmm7Wq { stack: 'TypeError: Cannot read property \'username\' of undefined\n    at _logUser (lib/const.js:9:16)\n    at _views.latest.terms (lib/views.js:16:34)\n    at _query (lib/views.js:300:22)\n    at Subscription._handler (imports/api/server/publications.js:105:22)\n    at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1768:12)\n    at DDP._CurrentPublicationInvocation.withValue (packages/ddp-server/livedata_server.js:1043:15)\n    at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1186:12)\n    at Subscription._runHandler (packages/ddp-server/livedata_server.js:1041:51)\n    at Subscription.subscriptionProto._runHandler (packages/mdg_meteor-apm-agent.js:2779:24)\n    at Session._startSubscription (packages/ddp-server/livedata_server.js:859:9)\n    at Session.sub (packages/ddp-server/livedata_server.js:625:12)\n    at packages/mdg_meteor-apm-agent.js:2642:34\n    at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1186:12)\n    at Session.sessionProto.protocol_handlers.sub (packages/mdg_meteor-apm-agent.js:2641:44)\n    at packages/ddp-server/livedata_server.js:559:43',
santisiri commented 6 years ago

I think this has already been fixed since it had to do on how some of the publications returned empty values instead of an array or collection when using the app logged off. Let me know if it happens again @vjrj.

vjrj commented 6 years ago

I still see some errors in latest builds, check this for instance: https://ci.comunes.org/job/sovereign/248/console

Exception while invoking method 'getUser' { stack: 'TypeError: Cannot read property \'_id\' of undefined\n

or this other log:

Exception while invoking method 'subsidizeUser' { stack: '[object Object]\n => awaited here:\n at Promise.await`

related with: https://github.com/DemocracyEarth/sovereign/issues/295

Yesterday I was studying the logs and code more in deep, I think that the problem is related to the way we create users using Meter.call to sendVerificationLink and subsidizeUser.

I think we can avoid this using: https://docs.meteor.com/api/accounts-multi.html#AccountsServer-onCreateUser on server side, to send the verification link etc prior to user insert. Take into account that we know the user._id in onCreateUser:

The user argument is created on the server and contains a proposed user object with all the automatically generated fields required for the user to log in, including the _id.

so we can call subsidizeUser etc only in server side safely.

Here a sample in other meteor project to send a welcome message (for instance) in onCreateUser.

Other option is to use after insert hooks. Some discussion about this topic.

santisiri commented 6 years ago

pinging @medied for this since he worked on that part of the code. I'll try to check it out when I find proper time then.