npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pouchdb-session-authentication

v1.4.0

Published

Plugin that forces session authentication for PouchDb http adapter

Downloads

5,521

Readme

PouchDb Session Authentication plugin

Enables session cookie authentication for pouchdb-adapter-http.

Installation

npm install pouchdb-session-authentication

Usage

const PouchDb = require('pouchdb-core');
PouchDb.plugin(require('pouchdb-adapter-http'));
PouchDb.plugin(require('pouchdb-session-authentication'));

const myDb = new PouchDB('http://admin:pass@mysite:5984/mydb');
const myOtherDb = new PouchDB(
  'http://mysite:5984/mydb', 
  { auth: { username: 'admin', password: 'pass' } 
});
const sessionDb = new PouchDB('http://mysite:5984/mydb', { session: 'existent session cookie' });

await myDb.allDocs();
await myOtherDb.allDocs();
await sessionDb.allDocs();

Overview

By default, pouchdb-adapter-http uses basic authentication for every outgoing request to CouchDb. CouchDb security configuration allows for setting the number of password hashing iterations, with the default number being 10000. The disclaimer for using a high number of iterations is:

When using hundreds of thousands of iterations, use session cookies, or the performance hit will be huge. (The internal hashing algorithm is SHA1, which affects the recommended number of iterations.)

Source

This plugin generates and stores a session cookie for pairs of user + CouchDb server instance and appends a Cookie header to all outgoing requests.

Integration should be seamless, the only requirement is adding the plugin after the pouchdb-adapter-http, with no additional necessary on the developer's part.

It supports authentication embedded in the CouchDb URL or as an additional option field when declaring the database.

It regenerates the session cookie on expiry and retries the last request, the client should not expect a failed request for an expired cookie.

When given a session parameter, a new session will not be requested, instead the passed session cookie will be used as session authentication. If both session and auth are provided then the auth will only be used if the session token has expired.

Testing

Testing requires docker and docker-compose to launch a CouchDb 3.3.3 container.

npm ci
npm run test
npm run integration