You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use db.login() to log the user in, do some operations (that work fine).
Then I wait 10 minutes and try again with the same db instance, but then the calls fail with HTTP 401 Unauthorized.
I don't see any traffic in Chrome's "Network" tab to indicate that tokens were refreshed.
This is what my CouchDb ini file looks like (maybe I'm missing something here?)
[couchdb]
single_node=true ; We set this, so that system dbs are created automatically.
[httpd]
enable_cors = true
[chttpd]
port = 31986
[cors]
credentials = true
origins = http://localhost:3000, https://localhost:31984
My javascript code that connects to the remote couchDb looks as follows. configureRemoteCouch and loginToRemoteCouch is only called once by my code, and from there I use the same remoteCouch instance:
import PouchAuth from 'pouchdb-authentication';
PouchDB.plugin(PouchAuth);
let remoteCouch = null;
function configureRemoteCouch(dbName) {
console.log('Configuring remote couchDb connection...');
remoteCouch = new PouchDB(
`http://localhost:31986/${dbName}`,
{
skip_setup: true
});
}
function loginToRemoteCouch(userName, password) {
console.log('Login local user to remote couchDb family db...';
remoteCouch.logIn(userName, password, function (err, response) {
if (err) {
console.error(err);
}
else {
// All good, do nothing.
}
});
}
The javascript code that pushes documents to the local pouchDb and then replicates to the remote looks as follows:
const createDbDocument = async () => {
if (!familyDbCreated) return;
console.log('Save document to local pouchDb...');
const localPouchDb = new PouchDB(state.familyDbName);
await localPouchDb.post({ // Some random document. This works fine every time.
timestamp: new Date()
});
console.log('Start replication...');
localPouchDb.replicate.to(remoteCouch); // This fails if I try after 10 minutes.
localPouchDb.replicate.from(remoteCouch);
console.log('Replicated.');
}
... this is the code where I see the problem. It works within the 10 minute period, but not once the period has elapsed.
Expected Behavior
I'd expect all calls to succeed. The first calls, done immediately after logging in, as well as additional calls after 10 minutes of inactivity.
I wasn't sure if I should re-use the remote PouchDb instance (eg. keep a "singleton"), but I did a little experiment, where I only do db.login once, but create a brand new remote instance every time I do a db.replicate.to. When I did this, the _session api was called every time with username and password. So it "worked", but made cookie auth besides-the-point, because it gets a new AuthSession cookie on every call.
willemodendaal
changed the title
PouchDb cookie does not auto-refresh after 10 minutes.
PouchDb auth cookie does not auto-refresh after 10 minutes.
Nov 18, 2020
[couch_httpd_auth]
allow_persistent_cookies = true
; 1 day = 24 * 60 * 60 = 86400 seconds (set timeout to at least 10 minutes but according to your needs)
timeout = 86400
require_valid_user=true
I use db.login() to log the user in, do some operations (that work fine).
Then I wait 10 minutes and try again with the same db instance, but then the calls fail with HTTP 401 Unauthorized.
I don't see any traffic in Chrome's "Network" tab to indicate that tokens were refreshed.
This is what my CouchDb ini file looks like (maybe I'm missing something here?)
My javascript code that connects to the remote couchDb looks as follows.
configureRemoteCouch
andloginToRemoteCouch
is only called once by my code, and from there I use the same remoteCouch instance:The javascript code that pushes documents to the local pouchDb and then replicates to the remote looks as follows:
... this is the code where I see the problem. It works within the 10 minute period, but not once the period has elapsed.
Expected Behavior
I'd expect all calls to succeed. The first calls, done immediately after logging in, as well as additional calls after 10 minutes of inactivity.
Current Behavior
Calls made after 10 minutes fail with HTTP 401.
Your Environment
The text was updated successfully, but these errors were encountered: