perfood / couch-auth

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

"Request processed" on register but nothing in the db #10

Closed Karalix closed 3 years ago

Karalix commented 3 years ago

Hi ! I have been testing SuperLogin over the weekend for an upcoming project but it seems I have reached a blocking point.

I am trying to make the code example from the README work with my instance of CouchDB on my distant server.

The /register POST seems OK

curl --request POST \
  --url http://localhost:3000/auth/register \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data '={
  "name": "Joe Smith",
  "username": "joesmith",
  "email": "joesmith@example.com",
  "password": "bigsecret",
  "confirmPassword": "bigsecret"
}'

{
  "success": "Request processed."
}

but then there is nothing appearing in the Fauxton and of course the next step gives me some kind of error

curl --request POST \
  --url http://localhost:3000/auth/login \
  --header 'Authorization: Basic am9lc21pdGg6Ymlnc2VjcmV0'

{
  "message": "Missing credentials"
}

And the CLI doesn't help me much as there is no error message at all, only POST /auth/register 200 516.158 ms - 32

On the CouchDB logs, there is only this POST /sl-users/_find 200 ok 5 when I perform the request.

My SuperLogin config is as following :

{
  dbServer: {
    protocol: 'https://',
    host: 'krlx.ovh:6984',
    user: 'admin',
    password: 'redacted',
    userDB: 'sl-users',
    couchAuthDB: '_users'
  },
  mailer: {
    fromEmail: 'alixducros@gmail.com',
    options: {
      service: 'Gmail',
      auth: {
        user: 'alixducros@gmail.com',
        pass: 'redacted'
      }
    }
  },
  userDBs: {
    defaultDBs: {
      private: ['supertest']
    }
  }
}
CouchDB 3.1.1
SuperLogin 0.14.1
Node 14

Maybe you have an idea of what I did wrong ? Anyway thanks for maintaining this project.

fynnlyte commented 3 years ago

Hi,

If you want to use application/x-www-form-urlencoded your request would need to look like this, which works for me with your setup:

curl --request POST \
  --url http://localhost:3000/auth/register \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'email=joesmith@example.com' \
  --data-urlencode 'password=bigsecret' \
 --data-urlencode 'confirmPassword=bigsecret'

Or you can simply use application/json instead:

curl --request POST \
  --url http://localhost:3000/auth/register \
  --header 'Content-Type: application/json' \                 
  --data '{"email": "joesmith@example.com", "password": "bigsecret", "confirmPassword": "bigsecret"}'

Nevertheless, I should add some logs and return an error if the validation fails with anything else than an email being in use.

Karalix commented 3 years ago

I works perfectly now and I feel pretty stupid for mixing urlencoded with my json object 😓

Would you welcome a pull request to make the Readme a bit more verbose/exhaustive around this part ?

fynnlyte commented 3 years ago

No worries, thanks for reporting. There should have been a Validation Error as answer, not a 200: request processed. The example part is a bit outdated anyway's, I'll update it together with my fix.