react-pouchdb icon indicating copy to clipboard operation
react-pouchdb copied to clipboard

Error when using `useFind` and `pouchdb-server`

Open embeddedt opened this issue 5 years ago • 2 comments

I'm using your library in a React project of mine and it's been working excellently for local databases. Thanks for putting this together!

Now I'm working on synchronizing the database with a pouchdb-server instance. The connection seems to work fine, but calls to useFind are now giving me 400 Bad Request errors when the library tries to access the /_find endpoint on the remote database.

Is there something special I need to do to make useFind work with pouchdb-server?

embeddedt avatar May 17 '20 20:05 embeddedt

Hi! Nice to hear. Thanks for the support!

There shouldn't be anything special to get started using a remote database. Todoapp seems to work with pouchdb-server and http://localhost:5984/todoapp as the database name.

In a real app it's usually necessary to modify the fetch options. I use pouchdb-server for development. Setup like this works well for me:

<PouchDB
  name="http://example.com/dbname"
  fetch={(url, opts) => {
    opts.headers.set('authorization', `Bearer ${token}`); // For external JWT auth
    return fetch(url, {
      ...opts,
      credentials: 'omit'
    });
  }}
>
  ...
</PouchDB>

Hope this helps, but if not, please post the request and response headers and let's have a look.

ArnoSaine avatar May 18 '20 20:05 ArnoSaine

Thanks for your reply. This is for a project I'm working on in my spare time so I likely won't have a chance to try your suggestion before the weekend. I'll let you know how it goes.

embeddedt avatar May 21 '20 18:05 embeddedt

I ended up abandoning this project so I'll close this as likely being something I did wrong on my end.

embeddedt avatar Jul 10 '23 20:07 embeddedt