perfood/couch-auth

TypeError: Cannot read property 'user' of undefined

sullyinc opened this issue · 4 comments

First, thanks for all your work on this library! I've been using it to get auth working quickly with couchdb.

Second, I'm seeing an error when attempting to register a new user with 0.14.0:

(node:79787) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'user' of undefined

To reproduce:
I think the relevant parts of my config are:

  local: {
    // Set this to true to disable usernames and use emails instead
    emailUsername: true,
  },

  userDBs: {
    defaultDBs: {
      private: ['user'],
      shared: []
    }
  }

Then, I issue the following request: The request succeeds with 200 OK

% curl -X POST \
  -d '{"email": "test@example.io", "password": "password1", "confirmPassword": "password1"}' \
  -H 'Content-Type: application/json' \
  http://localhost:3001/auth/register

{"success":"Request processed."}           

But looking at the server logs I see the following stacktrace:

POST /auth/register 200 26.512 ms - 32
(node:79787) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'user' of undefined
    at DBAuth.getDBConfig (/[path]/node_modules/@sl-nx/superlogin-next/lib/dbauth/index.js:199:101)
    at /Users/asullivan/Development/spock-express/node_modules/@sl-nx/superlogin-next/lib/user.js:1001:46
    at Array.forEach (<anonymous>)
    at processUserDBs (/[path]/node_modules/@sl-nx/superlogin-next/lib/user.js:1000:20)
    at SuperLogin.addUserDBs (/[path]/node_modules/@sl-nx/superlogin-next/lib/user.js:1018:9)
    at SuperLogin.insertNewUserDocument (/[path]/node_modules/@sl-nx/superlogin-next/lib/user.js:294:30)
    at /[path]/node_modules/@sl-nx/superlogin-next/lib/user.js:258:46
(node:79787) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:79787) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Do you know what this could be? I tried clearing everything in sl-users and _users but still no luck.

Hi,

  • did this happen with a „clean” setup of 0.14.0 or did you upgrade from a previous version? When upgrading from 0.13.X or the old superlogin, manual migration is required, check the Changelog.
  • can you verify that the view auth/expiredKeys exists in the sl-users DB?
  • If not, can you provide an example repo to reproduce the error from scratch?

This shouldn't happen if everything is set up correctly.

Ah I think a config entry under userDBs for the model is still expected, eventhough it should not be necessary anymore. Can you try this as a workaround?

 userDBs: {
    defaultDBs: {
      private: ['user'],
      shared: []
    },
   model: {
     user: {}
   }
  }

Can you install this commit and let me know whether it fixed the issue without modifying the config?

npm i github:@sl-nx/superlogin-next#dfc9151

Fixed in the most recent release.