feathers-accounts
A FeathersJS plugin for simple user signup & login. Its goal is to make authentication easy, while making it easy to use feathers-hooks
for access control.
In its current version it only includes the server-side solution. A drop-in client utility is in the master plan.
Getting Started
Setting up feathers-accounts
is a three-step process.
1 - The User Service
feathers-accounts
uses a regular Feathers service to store accounts. You can pass it any Feathers service that supports at least the find
and update
methods. Here is an example of creating a feathers-mongodb
service:
var fMongo = ;var db = mongo;var userStore = ;
2 - The Config Object
The config object is used to configure plugins for auth and communication. There is currently only one plugin, the local
plugin, which allows email/password login using tokens instead of cookies. Also for now, feathers-accounts
is tightly coupled with the Mandrill email service, so the config object must have all of the attributes in the example below in order to work properly. In the below example, we are passing the userStore
that we just created, above, in as the config.store
attribute.
var config = store:userStore // Using the `local` plugin for token login. local: id:'_id' // Make your own unique secret. Used for token generation. secret:'A1E7YYKDOYWs9t9Bf2JbJsatbNaplF01' // The Mandrill configuration. mandrill: key:'fVyBlahBlahbFMGBlahx-A' from_email:'marshall@creativeideal.net' from_name:'Feathers Tuts' subaccount:'feathers-tuts' website:'' verifyURL:'/#!verify' ;
3 - Register the Plugin
The final step is to register the plugin with the feathers app. Use this first line of code to turn on all of the REST routes for user signup and authentication:
// Turn on REST routes for authentication.app
This next bit will setup authentication data on new Socket.io connections that use an auth token string:
// Adds the authentication data to new socket connections.app
4 - Use feathers-hooks for Access Control
// TODO: Finish documenting feathers-hooks
Bringing it all together
Here is an example server.js file to get you started:
'use strict'; var feathers = hooks = mongo = fMongo = bodyParser = accounts = ; var db = mongo;var userStore = ; var config = store:userStore // Using the `local` plugin for token login. local: id:'_id' // Make your own unique secret. Used for token generation. secret:'A1E7YYKDOYWs9t9Bf2JbJsatbNaplF01' mandrill: key:'fVyBlahBlahbFMGBlahx-A' from_email:'marshall@creativeideal.net' from_name:'Feathers Tuts' subaccount:'feathers-tuts' website:'' verifyURL:'/#!verify' ; var app = // Turn on REST routes for authentication. // Adds the authentication data to new socket connections. // Enable hooks after auth. Lets us handle auth inside hooks. ; // Create a todos service.var todoStore = ; app; // Start the server.var port = 8080;app;