Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A user management library for Derby
JavaScript
Branch: master
Failed to load latest commit information.
lib fix tests by using mongo instead of memory driver
test increase test timeouts
.gitignore
.travis.yml add 0.12 to travis
LICENSE update readme, add license
README.md
index.js begin migrating to 0.6
package.json

README.md

Derby User

A user library for Derby JS. It uses Passport for authentication and Credential for storing hashes.

Build Status

Installation

$ npm install derby-user --save

Server Usage

In your server file, add the middleware:

var user = require('derby-user');

expressApp
  // ...
  // ...
  // cookieParser, session, transport, model, bodyParser...
  .use(user.init())
  // ...
  // ...
  // app.router, expressApp.router
  .use('/user', user.routes())

App Usage

Example route:

// subscribe to current user in each route
app.get('*', function (page, model) {
  var userId = model.get('_session.user.id');
  var user = model.at('users.' + userId);
  model.subscribe(user, function (err) {
    if (err) return next(err);
    model.ref('_page.user', user);
    next();
  });
});

Example signin controller function:

app.proto.signin = function (username, password) {
  var model = this.model;
  $.post('/user/signin', {
    username: username,
    password: password
  }).done(function (data) {
    model.set('_session.user.id', data.user.id);
    app.history.push('/');
  });
};

Example signin view:

<form on-submit="signin(username, password)">
  <label>username</label>
  <input type="text" value="{username}">
  <label>password</label>
  <input type="password" value="{password}">
</form>
Something went wrong with that request. Please try again.