# pouchdb-users

> PouchDB plugin to simulate CouchDB’s _users database behavior

Latest version **1.0.6** (published 2017-06-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install pouchdb-users
pnpm add pouchdb-users
yarn add pouchdb-users
bun add pouchdb-users
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-06-11 |
| First published | 2015-12-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | The Hoodie Community |
| Maintainers | hoodie |
| Keywords | couchdb, pouchdb, plugin, users, authentication |

## Links

- npm: https://www.npmjs.com/package/pouchdb-users
- Repository: https://github.com/hoodiehq/pouchdb-users
- Homepage: https://github.com/hoodiehq/pouchdb-users#readme
- Issues: https://github.com/hoodiehq/pouchdb-users/issues
- npm.io page: https://npm.io/package/pouchdb-users

## Dependencies (4)

- [lie](https://npm.io/package/lie.md) ^3.1.1
- [secure-random](https://npm.io/package/secure-random.md) ^1.1.1
- [pouchdb-wrappers](https://npm.io/package/pouchdb-wrappers.md) ^1.3.6
- [pouchdb-bulkdocs-wrapper](https://npm.io/package/pouchdb-bulkdocs-wrapper.md) ^1.0.2

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2017-06-11
- 1.0.5 — 2017-06-11
- 1.0.4 — 2017-06-02
- 1.0.3 — 2015-12-23
- 1.0.2 — 2015-12-21
- 1.0.1 — 2015-12-15
- 1.0.0 — 2015-12-15

## README

# pouchdb-users

> PouchDB plugin to simulate CouchDB’s \_users database behavior

[![Build Status](https://travis-ci.org/hoodiehq/pouchdb-users.svg?branch=master)](https://travis-ci.org/hoodiehq/pouchdb-users)
[![Coverage Status](https://coveralls.io/repos/hoodiehq/pouchdb-users/badge.svg?branch=master)](https://coveralls.io/r/hoodiehq/pouchdb-users?branch=master)
[![Dependency Status](https://david-dm.org/hoodiehq/pouchdb-users.svg)](https://david-dm.org/hoodiehq/pouchdb-users)
[![devDependency Status](https://david-dm.org/hoodiehq/pouchdb-users/dev-status.svg)](https://david-dm.org/hoodiehq/pouchdb-users#info=devDependencies)

`pouchdb-users` hashes passwords and ensures doc formats as CouchDB does it with
its `_users` database, so that any database and leveldown adapter can be used
besides CouchDB for persisting user accounts.

## Example

```js
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-users'))

var db = new PouchDB('my-users', { db: require('memdown') })

db.installUsersBehavior()
  .then(function () {
    return db.put({
      _id: 'org.couchdb.user:test',
      type: 'user',
      name: 'test',
      password: 'secret'
    })
  })
  .then(function () {
    return db.get('org.couchdb.user:test')
  })
  .then(function (doc) {
    // doc looks like this:
    // {
    //    "_id": "org.couchdb.user:test",
    //    "_rev": "1-e7172e5a925427378af944674c1c95d0",
    //    "password_scheme": "pbkdf2",
    //    "iterations": 10,
    //    "type": "user",
    //    "name": "test",
    //    "roles": [],
    //    "derived_key": "a13593349e8838c2349a463e570be80a1064cc4a",
    //    "salt": "9c9e3161c6b71455af35e80eb1152db0"
    // }
  })
```

The above example works the same against a couchdb

```js
var db = new PouchDB('http://localhost:5984/_users', {
  auth: {
    username: 'admin',
    password: 'secret'
  }
})

db.installUsersBehavior()
  .then(function () {
    return db.put({
      _id: 'org.couchdb.user:test',
      type: 'user',
      name: 'test',
      password: 'secret'
    })
  })
```

## How it works

`pouchdb-users` does not add any additional methods to `db`, but hooks into
`db.put`, `db.post` and `db.bulkDocs` to modify the document before storing it
in the database.

Note that `pouchdb-users` does not implement any access restrictions, there
is no user context available in PouchDB.

## Testing

Local setup

```
git clone git@github.com:hoodiehq/pouchdb-users.git
cd pouchdb-users
npm install
```

Run all tests and code style checks

```
npm test
```

Run specific tests only

```
node tests/specs/debug.js # run .debug() unit tests
```

**PROTIP™:** pipe output through a [pretty reporter](https://www.npmjs.com/package/tape#pretty-reporters)

### License

[Apache-2.0](https://github.com/hoodiehq/hoodie/blob/master/LICENSE)

---
_Source: https://npm.io/package/pouchdb-users · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
