level-users

Store and get users. Salt their passwords, persist them to disk.

SYNOPSIS

Store and get users. Salt their passwords, persist them to disk.

USAGE

Pass a leveldb instance to the Users constructor. I recommend using sublevel to bucket your database's meta data and multilevel if your database is on the network. See level-user for client side support.

var db = level('./db')
var users = Users(db)

API

Create a new user by passing a user object. Only username is required. When a new user is created, a uuid is returned.

var user = {
  username: 'test',
  password: 'pass',
  foo: 100,
  email: 'test@tap.com'
}
 
users.create(user, function(errid) {
  // id => 'a3a1d270-75fe-4bfc-a2bc-e358903bc540' 
})

Removes a user and any indexs that have been created for their records

users.remove(id, function(err) {
})

Add indexes that can be used to get a user. You can use any arbitrary field that is in your user object. In this example we index on email.

users.addIndexes(['email'], function(err) {
})

Get a user by their uuid. Returns the user object and a put method that can be used to update the user data.

users.get(id, function(erruserput) {
})

Here's an example using an index. returns the user's id.

users.get({ email: 'test@tap.com' }, function(errid) {
})

Find out if the proposed password matches with the a salt stored for a given user id. If auth is successful, you get a the user object and a put function so that you can write some new user information. If the auth fails, the user object will be null.

users.auth(id, password, function(erruserput) {
  user.isCool = true
  put(user, function(err) {
    // ... 
  })
})

Add groups to a user, this is just sugar for array index checking.

users.addGroups(id, ['super','rooty'], function(erruserput) {
})

Remove groups from a user, also just sugar for array index checking.

users.removeGroups(id, ['rooty'], function(erruserput) {
})