# account-couch

> Implement the accounts interface using a couchdb backend

Latest version **1.0.1** (published 2013-05-01) · BSD license · 0 weekly downloads

## Install

```sh
npm install account-couch
pnpm add account-couch
yarn add account-couch
bun add account-couch
```

## 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.1 |
| Published | 2013-05-01 |
| First published | 2013-04-30 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Noah Isaacson |
| Maintainers | clewfirst |
| Keywords | accounts, register, couch, couchdb, cradle |

## Links

- npm: https://www.npmjs.com/package/account-couch
- Repository: https://github.com/nisaacson/account-couch
- npm.io page: https://npm.io/package/account-couch

## Dependencies (4)

- [account](https://npm.io/package/account.md) ~1.0.0
- [bcrypt-nodejs](https://npm.io/package/bcrypt-nodejs.md) 0.0.3
- [couch-profile](https://npm.io/package/couch-profile.md) ~1.0.16
- [required-keys](https://npm.io/package/required-keys.md) ~1.0.5

## Recent versions

- 1.0.1 (latest) — 2013-05-01
- 1.0.0 — 2013-05-01
- 0.0.7 — 2013-05-01
- 0.0.6 — 2013-05-01
- 0.0.5 — 2013-05-01
- 0.0.4 — 2013-05-01
- 0.0.3 — 2013-05-01
- 0.0.2 — 2013-04-30
- 0.0.1 — 2013-04-30

## README

# Account Couch
Implement the account interface using a couchdb backend with the couch-profile module

[![Build Status](https://travis-ci.org/nisaacson/account-couch.png?branch=master)](https://travis-ci.org/nisaacson/account-couch)
[![Dependency Status Status](https://david-dm.org/nisaacson/account-couch.png)](https://david-dm.org/nisaacson/account-couch)

# Installation
Install the module by executing
```bash
npm install -S account-couch
```

You will also need the views provided by the [couch-profile](https://github.com/nisaacson/couch-profile) module. You can add these to your couchdb database using the [couchdb-update-views](https://github.com/nisaacson/couchdb-update-views) module.

```bash
# create a couchdb database named account_couch_test
curl -X PUT localhost:5984/account_couch_test
# install the couchdb-update-views module globally so the couchdb-update-views command is available on the command line
npm install -g couchdb-update-views
# add the couch-profile views to the newly created account_couch_test database
couchdb-update-views --config test/config.json --docsDir node_modules/couch-profile/docs
```

You can perform the steps listed above by executing the travis before_install script with the command

```bash
script/createDatabase.sh
script/createViews.sh
```


# Usage
The account couch module implements and exports the following interface functions:

* `login`
* `register`
* `serializeUser`
* `deserializeUser`
* `removeUser`


## Register

To register a new account, pass an object with an `email`,  and a `password`

```javascript
var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
account.register(data, function (err, reply) {
  if (err) {
    inspect(err, 'error registering user account')
    return
  }
  inspect(reply, 'user account created correctly'
})
```

## Login

To login an existing account, pass an object with an `email`,  and a `password` fields set

```javascript
var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
account.login(data, function (err, reply) {
  if (err) {
    inspect(err, 'error performing login for user account')
    return
  }
  inspect(reply, 'user account created correctly'
})
```

## Serialize User

To serialize an existing user account profile, pass a profile object to the serializeUser method. You will get back the `_id` of the profile in the couchdb database

```javascript
var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
// get the profile by logging in
account.login(data, function (err, profile) {
  if (err) {
    inspect(err, 'error performing login for user account')
    return
  }
  inspect(profile, 'user account profile')
  account.serializeUser(profile, function (err, reply) {
    if (err) {
      inspect(err, 'error performing login for user account')
      return
    }
    inspect(reply, 'profile serialized to _id')
  })
})
```

## Deserialize User

To deserialize an existing user account profile, pass an `_id` of the profile in the couchdb database

```javascript
var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
// an _id of a user profile in the couchdb database
var id = 'fooID'
account.deserializeUser(id, function (err, profile) {
  if (err) {
    inspect(err, 'error performing login for user account')
    return
  }
  inspect(profile, 'user account profile')
})
```



## Remove User

To completly remove an existing user account profile from the couchdb database, pass an object containing the `email` and `password` of the user account profile to be removed from the couchdb database

```javascript
var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
account.removeUser(data, function (err) {
  if (err) {
    inspect(err, 'error removing profile')
    return
  }
  inspect('user account profile removed')
})
```

# Test
To run the test suite execute

```bash
# install development dependencies
npm install
# run tests
npm test
```

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