perfood / couch-auth

Powerful authentication for APIs and apps using CouchDB (or Cloudant) with Node >= 14
MIT License
66 stars 19 forks source link

Document update conflict upon login #83

Closed chrispahm closed 6 months ago

chrispahm commented 6 months ago

Hey @fynnlyte,

I'm facing an issue where a user login fails with an internal server error. Upon inspecting the case I found that the /auth/login route repsonds with an error message which seems to be an upstream 409 error from CouchDB.

Here's the anonymised response I receive when trying to login with the given credentials (status 500):

{
  "scope": "couch",
  "statusCode": 409,
  "request": {
    "method": "post",
    "headers": {
      "content-type": "application/json",
      "accept": "application/json",
      "user-agent": "XXXXXX",
      "Accept-Encoding": "deflate, gzip"
    },
    "auth": {
      "username": "XXXXXX",
      "password": "XXXXXX"
    },
    "qsStringifyOptions": {
      "arrayFormat": "repeat"
    },
    "url": "http://localhost:5984/_users",
    "paramsSerializer": {},
    "data": "{\"_id\":\"org.couchdb.user:XXXXXX\",\"type\":\"user\",\"name\":\"XXXXXX\",\"user_uid\":\"XXXXXX\",\"user_id\":\"XXXXXX\",\"expires\":123456789,\"roles\":[\"XXXXXX\",],\"provider\":\"local\",\"password_scheme\":\"pbkdf2\",\"iterations\":10,\"salt\":\"XXXXXX\",\"derived_key\":\"XXXXXX\"}",
  },
  "errid": "non_200",
  "name": "Error",
  "description": "Document update conflict.",
  "error": "conflict",
  "reason": "Document update conflict."
}

I know the user tried to reset their password, which they said didn't work. I then reset their password to a default password using the changePassword method. This seemed to work (got no errors), but now it seems the internal state of this users doc is broken.

Any idea of this can be fixed? Thanks a lot for your help!

chrispahm commented 6 months ago

Alright, found that I was still running v.0.19.0 of couch-auth which was missing this section of the storeKey function that deals with 409 errors.

Updated to the latest version and the issue is gone! Again, thanks for this wonderful package 😊