Skip to content

mcollina/users-pg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

users-pg

Manage Users, with node and postgres

Install

npm install @matteo.collina/users-pg --save

API


buildusers(connectionString)

The factory for the users module, you can just pass through a pg connection string.

Example:

var connString = 'postgres://localhost/users_tests'
var users = require('@matteo.collina/users-pg')(connString)

users.put(object, callback(err, user))

Adds or updates an user. An user can have three properties:

  1. the 'id', which needs to be set only for existing users
  2. the 'username'
  3. the 'status', which can be any of 'wait', 'operational' and 'error'.

Validation is provided by Joi, and a Joi error object will be provided in case of validation errors.

The returned user includes the id, if missing.


users.get(id, callback(err, user))

Fetches an users, returns a boom.notFound if not present.


users.authenticate(user, callback(err, result, user))

Fetches a user, hashes the password with the stored salt and matches it against the database. result is true if the match is successful, false otherwise. Returns boom.notFound if not present.


users.createSchema(callback(err))

Create the schema in PostgreSQL for this module.


users.dropSchema(callback(err))

Drop the schema in PostgreSQL for this module.

License

MIT

About

Store and authenticate users with postgres

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published