Closed leonid-shevtsov closed 1 year ago
There are some issues in the tests:
fetch-cookie
version; either pouchdb-node
will be updated, or we can make a custom build and use the correct fetch-cookie
. Though until pouchdb-node
is updated, pouchdb-authentication
will still error against the official build, so maybe no sense in doing anything custom.Can we use the api.fetch
that pouchdb-adapter-http exposes?
https://github.com/pouchdb/pouchdb/blob/858660e9b37959d96eebf667ea9b8b1273f0d62c/packages/node_modules/pouchdb-adapter-http/src/index.js#L437
That one also supports 'overloading' so a user can give their own fetch function to modifiy the request.
We recently found out that we needed to overrule a signup request when logged in as a non-admin user to be able to prevent credentials from being included. I don't really see a way of doing this with your setup.
If we switched to api.fetch
it might also prevent the need for getBasicAuthHeaders
, since those seem to be handled there:
https://github.com/pouchdb/pouchdb/blob/858660e9b37959d96eebf667ea9b8b1273f0d62c/packages/node_modules/pouchdb-adapter-http/src/index.js#L169-L176
@jlami good point.
I was already using the fetch from pouchdb-adapter-http
, which is available through PouchDB.fetch
and in db.fetch
, so it did support overloading
However, I did some digging and turns out, if you use db.fetch
, you can pass it paths instead of URLs, and it will build the URL for you. And as you said, it also sets auth headers and enables cookies. This removes a lot of code from pouchdb-authentication
.
Unfortunately this PR won't work until there's a new version of PouchDB released; this fix in particular is absolutely necessary.
I made a PR to pouchdb
to expose the fetchJSON API so I can remove the implementation I made in this one.
Any updates on this?
Thank you @leonid-shevtsov. Sorry for the very late merge...
No worries! Thank you so much for merging.
I've seen #238, but it looked abandoned, and there was refactoring seemingly unrelated to PouchDB 7. I figured it's easier to start over. Sorry about that.
pouchdb-ajax
andpouchdb-promise
pouchdb-memory
build withpouchdb-browser
andpouchdb-node
.db.fetch
, and not any other instance offetch
(such as an additional polyfill, or even imported frompouchdb-fetch
). This will let this plugin cooperate with other plugins that might customizefetch
behavior. So:pouchdb-fetch
package, since it's baked intopouchdb-browser
and other builds.fetch
works with promises naturally, it's more appropriate to define the API in terms of promises as well. So to support the callback style, I've defined atoCallback
helper which does roughly the opposite oftoPromise
and enables both the promise and the callback API styles.fetchJSON
- a wrapper aroundfetch
that receives and returns JSONs. Then I've looked and, of course,pouchdb-adapter-http
has a very similar function, but it's private. Perhaps some day we can extract and reuse it.Needless to say, this changeset is not compatible with PouchDB 6 anymore.