zemirco / lockit

Authentication solution for Express
439 stars 48 forks source link

Custom Adapter #15

Closed bmac closed 10 years ago

bmac commented 10 years ago

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.

zemirco commented 10 years ago

Yes, that should be possible.

You just have to make sure your custom adapter has the same syntax as the other ones, i.e.

// create new user
adapter.save('john', 'john@email.com', 'secret', function(err, user) {});

// find user
adapter.find('name', 'john', function(err, user) {});

// update user
adapter.update(user, function(err, user) {});

// remove user
adapter.remove('john', function(err, res) {});

I will then change index.js#L48 and make the adapter configurable. Maybe add another field to exports.db in config.js

exports.db = {
  url: 'postgres://127.0.0.1:5432/',
  name: 'users',
  collection: 'my_user_table',
  adapter: [adapter name]
};

[adapter name] would be your custom adapter on npm. Does that work for you?

bmac commented 10 years ago

That should work for me. Thanks.

zemirco commented 10 years ago

No worries, thank you for the good idea!

I'll put it in the next release.

zemirco commented 10 years ago

done - https://github.com/zemirco/lockit/commit/82289d0e3d58e9e3eef720012ee42aa4f963834e