Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authorization error due to pouchdb change #840

Closed
barbalex opened this issue Oct 13, 2018 · 9 comments
Closed

authorization error due to pouchdb change #840

barbalex opened this issue Oct 13, 2018 · 9 comments

Comments

@barbalex
Copy link

barbalex commented Oct 13, 2018

Case

This is an issue in PouchDB and https://github.com/pouchdb-community/pouchdb-authentication that raises issues for people using rxdb.

I am raising this here to inform others that may run into this.

There is a workaround described here: pouchdb-community/pouchdb-authentication#239 (comment) that could maybe be applied to rxdb for as long as the issues in PouchDB and pouchdb-authentication are not resolved.

Related issues:

Issue

Authorization using cookies does not work.

Info

Code

this sync:

userDb.user.sync({
      remote: `http://localhost:5984/user_test_at_test_p_ch/`,
      options: {
        live: true,
        retry: true,
      },
      query: userDb.user
        .find()
        .where('type')
        .eq('user'),
    })

results in:

http://localhost:5984/user_test_at_test_p_ch/ 401 (Unauthorized)

after logging in:

import PouchDB from 'pouchdb-browser'
import pouchdbAuthentication from 'pouchdb-authentication'

PouchDB.plugin(pouchdbAuthentication)

const authDb = new PouchDB(couchUrl())
await authDb.logIn(email, password)
@barbalex
Copy link
Author

I tried forcing pouchdb and rxdb to always include credentials:

PouchDB.defaults({
  fetch(url: any, opts: any) {
    opts.credentials = 'include'
    return (PouchDB as any).fetch(url, opts)
  },
} as PouchDB.Configuration.RemoteDatabaseConfiguration)

and:

 await userDb.collection({
  name: 'user',
  schema: userDocSchema,
  pouchSettings: {
    fetch(url: any, opts: any) {
      opts.credentials = 'include'
      return (PouchDB as any).fetch(url, opts)
    },
  } as PouchDB.Configuration.RemoteDatabaseConfiguration,
})

but that does not solve the issue.

@pubkey
Copy link
Owner

pubkey commented Oct 13, 2018

A quick workaround could be to remove rxdbs pouchdb-folder and install an older version of pouchdb.

@barbalex
Copy link
Author

even though it would be a breaking change before? (v6.x versus v7)

@barbalex
Copy link
Author

I tried installing [email protected] and enforcing it's use by adding it as resolution in package.json (using yarn). But cookies are still not sent.

@barbalex
Copy link
Author

Went back to [email protected] and [email protected]. Still no cookies sent.

Then I deleted the pouchdb-js file in node_modules/rxdb/dist/lib/ and also in the src folder. Still no cookies sent.

My only temporary but horrible hack is to not write members into the security docs of the databases I am working with. Hoping that this will all work, once pouchdb and pouchdb-authentication update.

This is now o.k. for me as this app is in development and not used in real life yet.

@pubkey
Copy link
Owner

pubkey commented Oct 21, 2018

I'm closing this. It should be fixed by the authentication-plugin, not by RxDB.

@pubkey pubkey closed this as completed Oct 21, 2018
@psolom
Copy link

psolom commented Nov 4, 2018

@barbalex have you found a workaround?

@barbalex
Copy link
Author

barbalex commented Nov 4, 2018

@servocoder nope, sadly not. I'm waiting for pouchdb and the authentication-plugin to solve it.

@hubgit
Copy link
Contributor

hubgit commented Nov 16, 2018

I've been able to work around this, not by setting pouchSettings.fetch as the RxDatabaseCreator types would suggest (which had no effect), but by setting fetch as a sync option:

collection.sync({
    options: {
        fetch: (url, opts) => PouchDb.fetch(url, {
            ...opts,
            credentials: 'include',
        })
    },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants