Add Authentication to your FeathersJS app.

Usage no npm install needed!

<script type="module">
  import alanpogFeathersAuthentication from 'https://cdn.skypack.dev/@alanpog/feathers-authentication';



Build Status Code Climate Test Coverage Dependency Status Download Status Slack Status

Add Authentication to your FeathersJS app.

feathers-authentication adds shared PassportJS authentication for Feathers HTTP REST and WebSockets services using JSON Web Tokens.


npm install feathers-authentication --save


Please refer to the Authentication documentation for more details:

Complete Example

Here's an example of a Feathers server that uses feathers-authentication for local auth. It includes a users service that uses feathers-mongoose. Note that it does NOT implement any authorization.

import feathers from 'feathers';
import hooks from 'feathers-hooks';
import bodyParser from 'body-parser';
import authentication from 'feathers-authentication';
import { hooks as authHooks } from 'feathers-authentication';
import mongoose from 'mongoose';
import service from 'feathers-mongoose';

const port = 3030;
const Schema = mongoose.Schema;
const UserSchema = new Schema({
  email: {type: String, required: true, unique: true},
  password: {type: String, required: true },
  createdAt: {type: Date, 'default': Date.now},
  updatedAt: {type: Date, 'default': Date.now}
let UserModel = mongoose.model('User', UserSchema);

mongoose.Promise = global.Promise;

let app = feathers()
  .use(bodyParser.urlencoded({ extended: true }))
  // Configure feathers-authentication

app.use('/users', new service('user', {Model: UserModel}))

let userService = app.service('users');
  create: [authHooks.hashPassword('password')]

let server = app.listen(port);
server.on('listening', function() {
  console.log(`Feathers application started on localhost:${port}`);

Client use

You can use the client in the Browser, in NodeJS and in React Native.

import io from 'socket.io-client';
import feathers from 'feathers/client';
import hooks from 'feathers-hooks';
import socketio from 'feathers-socketio/client';
import localstorage from 'feathers-localstorage';
import authentication from 'feathers-authentication/client';

const socket = io('http://localhost:3030/');
const app = feathers()
  .configure(socketio(socket)) // you could use Primus or REST instead
  .configure(authentication({ storage: window.localStorage }));

  type: 'local',
  'email': 'admin@feathersjs.com',
  'password': 'admin'
  console.log('Authenticated!', result);
  console.error('Error authenticating!', error);


Copyright (c) 2016

Licensed under the MIT license.