GithubHelp home page GithubHelp logo

lockit's Introduction

Lockit

Build Status NPM version Dependency Status

Lockit is an authentication solution for Express. Check out the demo.

It consists of multiple single purpose modules:

Table of contents

Quickstart

  1. Create new Express app.

express

  1. Install Lockit and sessions via npm.

npm install && npm install lockit cookie-session --save

  1. Use lockit and cookie-session in your Express app.js.
var cookieSession = require('cookie-session');
var Lockit = require('lockit');
var lockit = new Lockit();

...
app.use(cookieSession({
  secret: 'my super secret String'
}));
app.use(lockit.router);
  1. Go to localhost:3000/signup

By default Lockit uses an in-memory SQLite database. So you don't have to set up any db. Lockit will just work. Check out the default example.

For production use a persistent data store!

Full installation

  1. Install and require

npm install lockit --save

var config = require('./config.js');
var Lockit = require('lockit');

var app = express();

// express middleware
// ...
// sessions are required
app.use(cookieParser());
app.use(cookieSession({
  secret: 'your secret here'
}));

var lockit = new Lockit(config);

app.use(lockit.router);

// you now have all the routes like /login, /signup, etc.
// and you can listen on events. For example 'signup'
lockit.on('signup', function(user, res) {
  console.log('a new user signed up');
  res.send('Welcome!');   // set signup.handleResponse to 'false' for this to work
});
  1. Add styles

Views are built with bootstrap. You can use your own ones though! Use Bootstrap CDN and add the following line to your layout.jade

link(rel='stylesheet', href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css')
  1. Install database adapter

npm install lockit-[DB]-adapter where [DB] can be

Database Command
CouchDB npm install lockit-couchdb-adapter
MongoDB npm install lockit-mongodb-adapter
SQL (PostgreSQL, MySQL, MariaDB or SQLite) npm install lockit-sql-adapter

If you use a SQL database you also have to install the connector.

npm install pg       # for postgres
npm install mysql    # for mysql
npm install sqlite3  # for sqlite
npm install mariasql # for mariasql

Configuration

You need a config.js somewhere in your app.

Database connection

Add the database connection string to your config.js.

// database settings for CouchDB
exports.db = 'http://127.0.0.1:5984/';        // connection string for database

// or if you want to use MongoDB
// exports.db = {
//   url: 'mongodb://127.0.0.1/',
//   name: 'test',
//   collection: 'users'  // collection name for MongoDB
// };

// PostgreSQL
// exports.db = {
//   url: 'postgres://127.0.0.1:5432/',
//   name: 'users',
//   collection: 'my_user_table'  // table name for SQL databases
// };

// MySQL
// exports.db = {
//   url: 'mysql://127.0.0.1:3306/',
//   name: 'users',
//   collection: 'my_user_table'
// };

// SQLite
// exports.db = {
//   url: 'sqlite://',
//   name: ':memory:',
//   collection: 'my_user_table'
// };

Sending emails

By default the email service is stubbed and no emails are sent. That means that you won't receive any signup and password reset tokens. You have to look them up in your database and call the routes manually (e.g. /signup/:token). To send emails you need an email server and you have to change the settings in your config.js:

  • emailType - usually nodemailer-smtp-transport
  • emailSettings - see nodemailer for more information

With mailgun you can send up to 10,000 emails per month for free.

exports.emailType = 'nodemailer-smtp-transport';
exports.emailSettings = {
  service: 'Mailgun',
  auth: {
    user: '[email protected]',
    pass: 'secret-password'
  }
};

Custom views

Lockit comes with built-in views which are based on Bootstrap. If you want to use your own custom views you can. It is dead simple.

Put them into your views folder, for example views/lockit/myLogin.jade. Then edit your config.js and set the path to your custom view.

exports.login = {
  route: '/login',
  logoutRoute: '/logout',
  views: {
    login: 'lockit/myLogin.jade',
    loggedOut: 'lockit/myLogoutSuccess.jade'
  }
};

The only thing you have to keep in mind is the structure. The login.views.login view, for example, needs a form element with two input fields. The method has to be POST and action should point to your login.route. The input fields have to have the names login and password. If something went wrong during the login process you'll get an error variable that you can use in your template.

Here is a minimalistic example for an alternative myLogin.jade.

extend /layout

block content
  h1 Login
  form(action="/login", method="POST")
    div
      label(for="login") Email or Username
      input(type="text", id="login", name="login", placeholder="Your email or username")
    div
      label(for="password") Password
      input(type="password", id="password", name="password", placeholder="Your password")
    if error
      p #{error}
    input(type="submit", value="Login")

For more information about each view see the views folder inside the different repositories. Make sure your view extends /layout which is different to your normal views. They extend layout without the slash. This is required to find the view.

Events

Lockit emits the most important events for user authentication. Those are

  • signup
  • login
  • logout
  • delete

You can use these events to intercept requests and implement some custom logic, like getting the gravatar before sending a response to the client.

signup

A new user signed up. The callback function has two arguments.

  • user is an object and contains information about the new user, like user.name or user.email.
  • res is the standard Express.js res object with methods like res.render and res.send. If you've set signup.handleResponse to false Lockit will not handle the response for you. You therefore have to send the response back to the client manually or otherwise it will wait forever.
lockit.on('signup', function(user, res) {
  // ...
});
login

A user logged in. Callback function this time has three arguments.

  • user is again the JSON object containing info about that particular user.
  • res is the normal Express.js response object with all properties and methods.
  • target is the redirect target route after a successful login, i.e. /settings
lockit.on('login', function(user, res, target) {
  // ...
});
forgot::sent

A user forgot the password and an email has been sent. Callback function has two arguments.

  • user is again the JSON object containing info about that particular user.
  • res is the normal Express.js response object with all properties and methods.
lockit.on('forgot::sent', function(user, res) {
  // ...
});
forgot::success

User has created a new password. Callback function has two arguments.

  • user is again the JSON object containing info about that particular user.
  • res is the normal Express.js response object with all properties and methods.
lockit.on('forgot::success', function(user, res) {
  // ...
});
logout

A user logged out. Same as above without the target string.

lockit.on('logout', function(user, res) {
  // ...
});
delete

A user deleted an account. Same callback as above.

lockit.on('delete', function(user, res) {
  // ...
});

REST API

In a single page application (SPA) all routing and template rendering is done on the client. Before version 0.5.0 Lockit caught relevant routes, like /login or /signup, and did the entire rendering on the server.

Starting with version 0.5.0 you're able to use Lockit as a REST API and communicate via JSON. All you have to do is set exports.rest in your config.js.

exports.rest = {
  // set starting page for single page app
  index: 'public/index.html',

  // use view engine (render()) or send static file (sendfile())
  useViewEngine: false
}

With REST enabled all default routes get a /rest prefix so you can catch /login on the client. To allow for true page refreshes (i.e. user is at /login and refreshes the page) all routes on the server, like /login and /signup, send the rest.index view to the client. From there your SPA has to take over.

Here is a short example how the process works.

  1. User sends GET request for /login
  2. Server has a route handler for this request and sends index.html back
  3. Client router takes over and renders /login page
  4. User enters credentials and submits the form
  5. Client controller catches submit and sends POST via AJAX request to /rest/login
  6. Server handles POST request and validates user credentials
  7. Server sends status code 200 or some JSON with error message
  8. Client reacts to JSON from server and redirects on success or shows error

I've built a simple example using AngularJS on the client side.

Sample config

If you want to go crazy and customize all the things you can:

// name for subject and email content
exports.appname = 'lockit - Test App';

// url for proper link generation
exports.url = 'http://localhost:3000';

// email settings (same as nodemailer)
exports.emailType = 'nodemailer-stub-transport';
exports.emailSettings = {
  service: 'none',
  auth: {
    user: 'none',
    pass: 'none'
  }
};

// whenever a library uses request under the hood (like nano in lockit-couchdb-adapter)
// the following values will be used
exports.request_defaults = {
  // proxy: 'http://someproxy'
};

// email template from npm
exports.emailTemplate = 'lockit-template-blank';

// render views or json for single page apps
exports.rest = false;

// or if you want to use rest
// exports.rest = {
//
//   // set starting page for single page app
//   index: 'public/index.html',
//
//   // use view engine (render()) or send static file (sendfile())
//   useViewEngine: false
//
// }

// signup settings
exports.signup = {
  route: '/signup',
  tokenExpiration: '1 day',
  views: {
    signup: '',         // input fields 'name', 'email' and 'password' | local variable 'error' | POST /'signup.route'
    linkExpired: '',    // message link has expired | input field 'email' | POST /'signup.route'/resend-verification
    verified: '',       // message email is now verified and maybe link to /'login.route'
    signedUp: '',       // message email has been sent => check your inbox
    resend: ''          // input field 'email' | local variable 'error' | POST /'signup.route'/resend-verification
  },
  handleResponse: true  // let lockit handle the response after signup success
};

// login settings
exports.login = {
  route: '/login',
  logoutRoute: '/logout',
  views: {
    login: '',          // input fields 'login' and 'password' | POST /'login.route' | local variable 'error'
    loggedOut: ''       // message that user logged out
  },
  handleResponse: true  // let lockit handle the response after login/logout success
};

// forgot password settings
exports.forgotPassword = {
  route: '/forgot-password',
  tokenExpiration: '1 day',
  views: {
    forgotPassword: '', // input field 'email' | POST /'forgotPassword.route' | local variable 'error'
    newPassword: '',    // input field 'password' | POST /'forgotPassword.route'/#{token} | local variable 'error'
    changedPassword: '',// message that password has been changed successfully
    linkExpired: '',    // message that link has expired and maybe link to /'forgotPassword.route'
    sentEmail: ''       // message that email with token has been sent
  }
};

// delete account settings
exports.deleteAccount = {
  route: '/delete-account',
  views: {
    remove: '',         // input fields 'name', 'phrase', 'password' | POST /'deleteAccount.route' | local variable 'error'
    removed: ''         // message that account has been deleted
  },
  handleResponse: true  // let lockit handle the response after delete account success
};

// lock account
// show warning after three failed login attempts
exports.failedLoginsWarning = 3;
// lock account after five failed login attempts
exports.failedLoginAttempts = 5;
// lock account for 20 minutes
exports.accountLockedTime = '20 minutes';

// public email address of your app
exports.emailFrom = '[email protected]';

// email signup template
exports.emailSignup = {
  subject: 'Welcome to <%- appname %>',
  text: [
    '<h2>Hello <%- username %></h2>',
    'Welcome to <%- appname %>.',
    '<p><%- link %> to complete your registration.</p>'
  ].join(''),
  linkText: 'Click here'
};

// email already taken template
exports.emailSignupTaken = {
  subject: 'Email already registered',
  text: [
    '<h2>Hello <%- username %></h2>',
    'you or someone else tried to sign up for <%- appname %>.',
    '<p>Your email is already registered and you cannot sign up twice.',
    ' If you haven\'t tried to sign up, you can safely ignore this email. Everything is fine!</p>',
    '<p>The <%- appname %> Team</p>'
  ].join('')
};

// resend signup template
exports.emailResendVerification = {
  subject: 'Complete your registration',
  text: [
    '<h2>Hello <%- username %></h2>',
    'here is the link again. <%- link %> to complete your registration.',
    '<p>The <%- appname %> Team</p>'
  ].join(''),
  linkText: 'Click here'
};

// forgot password template
exports.emailForgotPassword = {
  subject: 'Reset your password',
  text: [
    '<h2>Hey <%- username %></h2>',
    '<%- link %> to reset your password.',
    '<p>The <%- appname %> Team</p>'
  ].join(''),
  linkText: 'Click here'
};

Features

  • responsive html email template: lockit-template-blank
  • support for wide range of databases out of the box
  • email address verification
  • account locking after too many failed login attempts
  • verification link expiration
  • failed login tracking
  • /login redirection when user is unauthorized
  • password hash generation with bcrypt
  • unit tests for all modules
  • serves proper HTML views or only JSON
  • events for most important happenings login, logout, signup and delete
  • implementation of lots of best pratices

Routes included

From lockit-signup

  • GET /signup
  • POST /signup
  • GET /signup/:token
  • GET /signup/resend-verification
  • POST /signup/resend-verification

From lockit-login

  • GET /login
  • POST /login
  • POST /login/two-factor
  • GET /logout

From lockit-forgot-password

  • GET /forgot-password
  • POST /forgot-password
  • GET /forgot-password/:token
  • POST /forgot-password/:token

From lockit-delete-account

  • GET /delete-account
  • POST /delete-account

Test

grunt

License

MIT

lockit's People

Contributors

zemirco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lockit's Issues

Demo Page Error

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

Mustache support?

Hello, there's a way to use Mustache + partials instead of jade as template engine?
Thanks.

Can't find Python executable "python"

Hello.

I am getting this error. I have tried installing python modules but I have a strong feeling that this isn't going to help and that I have to do something outside of node.js

This is an image of the error:
Any help would be appreciated. Thank you!

screen

Config.js placement?

You mention in the docs:

You need a config.js somewhere in your app.

But its not mentioned where this file is to be referenced or placed.

Document / implement -- Custom error messages

Much of lockit is configurable. Thanks for that!

However, there are a few things that are still hard-coded, such as some of the error messages.

It would be great if these were also customizable.

Allow custom views

Find a solution for rendering / passing in custom views / jade files.

Thanks i love lockit!!!!

Thanks for this.

A couple questions:

I got this working with mailgun and cloudant and it just works, what do you recommend to write the actions after every action, redirection and stuff? how do you really secure a route? how do i change what happen on user registration? i want the database created at registration to be called something different and hace a particular design on it, how can i accomplish this?

Error: Cannot find module 'xtend'

I've tried to get the example app up and running but keep getting the following message:

Error: Cannot find module 'xtend'

Node v0.10.24
NPM v1.3.21
grunt-cli v0.1.11

Thanks.

Making the cookie persistant

Hi all, I am working on my first nodejs project so I'm still pretty new to all this, but I really enjoy working with lockit.

I'm trying to make the login persistant by changing the cookie expiration date, and can't find the solution... Should it be added as a config var ?

Make REST work

Instead of rendering views with res.render use res.json to communicate with the client.

In the config activate REST by setting exports.rest = true.

Non-restful lockit not work with restful lockit

Hi zemirco,
I want to use a restful lockit with a non-restul lockit, which feeds all static pages while listen to ajax requests. There is no option to disable restful lockit from rendering, which make restful lockit won't work with non-restful lockit.
There are two approach to make it work, one is add options to add restful routers to a non-restful lockit, and the other is to add an option to disable rendering. I think the second approach is more clear.

Add one line to Lockit.prototype.rest

if (!this.config.rest.index) return;

This will prevent render pages if config.rest.index is not set.

Then I can use lockit as follow:

var Lockit = require('Lockit');
var express = require('express');
var restConfig;
var config;
var lockit = new Lockit(config);
var restLockit = new Lockit(restConfig);
app = express();
app.use(lockit.router)
app.use(restLockit.router);

Custom Adapter

Hi @zemirco. Awesome project! This is exactly what I've been looking for.

I was wondering if it would be possible to support a the ability to specify a custom adapter module? It looks like the getDatabase function restricts the possible adapter modules to the existing lockit-*-adapter family. My use case is I have a project that uses knex to access a postgress database and I'd like to keep all of my table migrations managed in the same place. So I'm a little wary about letting the lockit-sql-adapter sync a table under the hood with sequelize.

Different lockit instances share a same config object

var Lockit = require('lockit');
var lockit_a = new Lockit(config_a);
var lockit_b = new Lockit(config_b);
console.log(lockit_a.config === lockit_b.config);

This will output a true, and it's caused by the code in lockit/index.js, line 34:

this.config = extend(true, configDefault, this.config);

All instances' config is point to configDefault.

When does a login session expire?

I see no configuration option in the documentation for this... What is the default expire time for each session?

Also, I noticed that if you log in twice with the same account on two different browsers (let's call them session1 and session2) and you log out from session2, then you will stay logged in in session1. Is this on purpose? I think it's a security problem.

Option to key/index off of email instead of username

It looks like name is intended to be username, and not the user's name, as it must be unique. Email must also be unique. It is common, and arguably a better user experience to only require email, as it already must be unique, instead of requiring two fields that have to be unique. Also, a user may forget the username they invented for your site---because it has to be unique for your site, so someone else could have taken the one they wanted---but they are less likely to forget their email address, and if email address requires verification, then nobody else can take their email address on your site.

Personally, I'd much rather just treat email address as username, and dispense with username field.

I suppose I could hack it by creating a hidden field and have javascript copy the email address into the username field just before form submit ... but I'd rather not even have a username field in my database.

Nope, can't hack it that way. Gives error: "Username may not contain any non-url-safe characters." .. but you can still hack it, just with a hack that looks worse by the minute .. javascript runs encodeURIComponent on the email address first, or you might just replace @ with -at- .. then pastes it into the hidden field.

use Router for Express 4.x

old

lockit(app);

new

app.use(lockit);

Where each module makes use of the new Router

var express = require('express');
var router = express.Router();

router.get('/signup', function(req, res, next) {
  // ...
});

module.exports = router;

No more passing around app.

Doubts

Hey!

I'm testing lockit and want to know about the login process...

How can I read about this process?

Is there a more complete documentation?

Thank you!

SMTP configuration not being passed to nodemailer

It seems that the emailSettings are not being passed on to the smtpTransport, since I specified them and digging in to Email.prototype.send, line 58, the emailSettings are not being passed on and, due to that, I got an ECONNREFUSED:

// send email with nodemailer
var transporter = nodemailer.createTransport(that.transport(options)); // options are not including my emailSettings
transporter.sendMail(options, function(err, res){
  if(err) return done(err);
  transporter.close(); // shut down the connection pool, no more messages
  done(null, res);
});

Why is there no unique index on username and email address?

I noticed on my mongodb installation for lockit that an index is set for user's id. That's good. However, lockit does not seem to set an unique index for username and email address which it should in my opinion or is there a specific reason not to do so?

Cannot find module: lockit-template-blank

It's really really easy to get this error, including if you just make a new express app using defaults and try the quick-start with lockit as per the instructions in lockit's readme:

npm start

lockit no db config found. Using SQLite.
lockit no email config found. Check your database for tokens.

/signup

..fill in the form and submit it..

->

Unhandled rejection Error: Cannot find module 'lockit-template-blank'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at new module.exports (/Users/dhall/projects/myapp/node_modules/lockit/node_modules/lockit-signup/node_modules/lockit-sendmail/index.js:16:19)

add role based access

hi,thanks for the module.i would like to ask if you have plan to add role based access to this module.thanks

Checking authentication after logih

Hi,

how can I check who the user is after he logged in?
I mean, when I hit another route, what method is available to get the user who logged in?
I checked the lockit-utils, but there is nothing like this there.
In most cases I'll need to know who the user calling a method is.
Thanks.

Cannot get full example to work

I tried the "full example" code:

var config = require('./config.js');
var Lockit = require('lockit');

var app = express();

app.use(cookieParser());
app.use(cookieSession({
  secret: 'secret'
}));

var lockit = new Lockit(config);

app.use(lockit.router);

// you now have all the routes like /login, /signup, etc.
// and you can listen on events. For example 'signup'
lockit.on('signup', function(user, res) {
  console.log('a new user signed up');
  res.send('Welcome!');   // set signup.handleResponse to 'false' for this to work
});

When I started the server it complained that express was undefined, so I installed express via npm and added:

var express = require('express');

and changed:

app.use(cookieParser());
app.use(cookieSession({
  secret: 'secret'
}));

to this:

app.use(express.cookieParser());
app.use(express.cookieSession({
  secret: 'secret'
}));

But now I get this. What's wrong?

lockit no email config found. Check your database for tokens.
/Users/valmar/dev/node/todolist/node_modules/lockit/node_modules/lockit-signup/index.js:40
  router.get(route, this.getSignup.bind(this));
        ^
TypeError: Cannot read property 'get' of undefined
    at new module.exports (/Users/valmar/dev/node/todolist/node_modules/lockit/node_modules/lockit-signup/index.js:40:9)
    at new module.exports (/Users/valmar/dev/node/todolist/node_modules/lockit/index.js:41:16)
    at Object.<anonymous> (/Users/valmar/dev/node/todolist/server.js:12:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Feature request: Passport.js integration for Facebook and Google auth

Thanks for writing Lockit, Mirco. You've included most of the features I'm looking for and it saves me from writing a lot of boilerplate code.

I think this component could benefit a lot from Passport.js integration, because it provides a uniform API for lots of authentication strategies. I would like to integrate Google and Facebook login into my application.

Document: Anything other than express-generator defaults, and Lockit fails to render

Lockit says it "comes with its own built-in views". This is sort-of correct. It is only correct if your express app uses the default view engine (jade). Lockit could actually render its own views with its own view-engine, independently of the main app. It might suffice to better document how to use your own views, and warn people that you will have to create custom views if you are not using jade as your view engine.

express --hbs --css stylus myapp
cd myapp && npm i
npm i lockit cookie-session

edit app.js to include

var cookieSession = require('cookie-session');
var Lockit = require('lockit');
var lockit = new Lockit();
...
app.use(cookieSession({secret: 'my super secret String'}));
app.use(lockit.router);

Visit localhost:3000/login

ERROR
Failed to lookup view "/Users/dhall/projects/myapp/node_modules/lockit/node_modules/lockit-login/views/get-login" in views directory "/Users/dhall/projects/myapp/views"

Why did you make GET /logout?

Explain me please why did you make logout using GET /logout?

It's not safe. Anyone can insert a picture <img src="http://yousite.com/logout" /> and your users will logged out.

It may be better to do POST /logout?

How do I change this in the config.js?

Waterline adapter

This is pretty neat, however the way the DB configurations are currently setup I found it quite tricky to make it work with my Sails.js site using the Waterline ORM. Basically I could bypass the ORM to connect directly separately to Mongo or Postgres or whatever the ORM adapter in waterline is pointed to as well. But I'd much prefer a lockit waterline adapter and just let the ORM to deal with those details.

Just a thought,

fix email

please add: "lockit-template-blank": "0.0.2"
to dependenies (not devDependencies)

The examples are all somewhat broken

All examples except "angular" are missing the error.jade view.

Update: don't know what I was doing wrong, after cleaning node modules an reinstalling it works running out of the box, save the missing error.jade file... so ignore the rest. Sorry about the fuss!

They also do not refer to the latest version of lockit and lockit's components which should be required as everything has been changed for Express 4.

Running the examples OOTB does not work for me unless I in app.js change var Lockit = require('../../'); to var Lockit = require('lockit'); and update the dependencies in package.json. But maybe I'm confused and have missed something else.

Database per user?

I see that a db lockit/user is created for each user...
This is a problem, if you have thousand of users. What is this DB used for?
Can this be changed?
Thanks.

Issue for waterline adapter

I have tried to add “query” method into adapter.js.

However the closure function in “query” method passing invalid arguments to another function. I guess this issue is causing by waterline’s adapter.js

Here is the flow .

Step 1 (call the query method from waterline’s adapter.js

note that key is “query”

adapter[key].apply(self, args);

Step 2

query: function (connection, collection, options, values, cb) {
this.connect(connectionName, function(err, db) {
});
}

Step 3

“cb” here is supposed to received the callback function but receive the other arguments instead (etc: collectionname);

connect: function (connectionName, cb) {
return cb();
}

Feature request: Token-based auth for REST API

Cookie-based auth doesn't work on Phonegap or Chrome packaged apps. It also leaves vulnerability to CSRF attacks.

A better strategy for an Angular-type SPA is to store a token in LocalStorage:
https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/

I would like the options to use either json web tokens (which don't require any session store) or a Redis-based token system. This is very easy to implement with Passport.

https://github.com/roblevintennis/passport-api-tokens

If I have some time over the next week I'll send you a pull request.

Express 4?

Would lockit work with Express 4?

Thanks

without email config, strange error

Hi,

Instead of using a config.js file, I'm just constructing the config in my app.js for a quite prototype. I know I don't have an email config, but this error is strange, why does it point to index.js:38?

lockit no email config found. Check your database for tokens.
assert.js:86
  throw new assert.AssertionError({
        ^
AssertionError: missing path
    at Module.require (module.js:363:3)
    at require (module.js:384:17)
    at new module.exports (/vagrant/node_modules/lockit/index.js:38:44)
    at Object.<anonymous> (/vagrant/app.js:20:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.