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

401 Unauthorized after successful login #268

Open
rehovicova opened this issue Jan 14, 2021 · 4 comments
Open

401 Unauthorized after successful login #268

rehovicova opened this issue Jan 14, 2021 · 4 comments

Comments

@rehovicova
Copy link

rehovicova commented Jan 14, 2021

Expected Behavior

I expect I can query the database after login without getting 401

Current Behavior

I am getting 401 after successful login

Code

let PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-authentication'))

let localDb = PouchDB(dbConfig.dbName);
let remoteDb = PouchDB(`http://${dbConfig.host}:5984/${dbConfig.dbName}`, { skip_setup: true })
remoteDb.login(dbConfig.username, dbConfig.password).then( result => {
    console.log(result) // <--- { ok: true, name: 'admin', roles: [ '_admin' ] }

    remoteDb.get(id).then( r => console.log(r)).catch( e => console.log(e));
    // Prints
    //  {
    //    error: 'unauthorized',
    //    reason: 'You are not authorized to access this db.',
    //     status: 401,
    //    name: 'unauthorized',
    //    message: 'You are not authorized to access this db.',
    //    docId: 'some_id'
    //  }

}).catch( e => logger.error(`${TAG}: ${e}`))

Your Environment

  • Version of PouchDB Authentication: 1.1.3
  • Version of PouchDB: 7.2.1
  • Platform name and version: Node.js 12.16.3

PS: I am connecting to the same database from a different project using JavaScript and PouchDB 7.2.1 and auth 1.1.3 (so exactly the same) and it works jut fine

@f5cs
Copy link

f5cs commented Feb 13, 2021

After login, the subsequent request does not carry the token of permission verification,i don't understand why there are such low-level mistakes here, but the problem can be solved in the following ways:
let remoteDb = PouchDB(
http://${dbConfig.host}:5984/${dbConfig.dbName},
{
skip_setup: true,
fetch:function(url,opts){
opts.headers.set('Authorization','Basic ' + btoa(dbConfig.username+":"+dbConfig.password'););
}
})

@ibalaji777
Copy link

no need
this package
PouchDB.plugin(require('pouchdb-authentication'))

new PouchDB('url', {
  auth: {
    username: 'user',
    password: 'pass'
  }
}

1 similar comment
@ibalaji777
Copy link

no need
this package
PouchDB.plugin(require('pouchdb-authentication'))

new PouchDB('url', {
  auth: {
    username: 'user',
    password: 'pass'
  }
}

@HZSamir
Copy link

HZSamir commented Dec 12, 2021

Any progress on this? Facing the same issue.

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