diff --git a/example/app.js b/example/app.js index 871cb1d..2deb057 100644 --- a/example/app.js +++ b/example/app.js @@ -1,18 +1,17 @@ const feathers = require('feathers'); const rest = require('feathers-rest'); const socketio = require('feathers-socketio'); -const primus = require('feathers-primus'); const hooks = require('feathers-hooks'); const memory = require('feathers-memory'); const bodyParser = require('body-parser'); -const errors = require('feathers-errors'); const errorHandler = require('feathers-errors/handler'); const auth = require('feathers-authentication'); const local = require('feathers-authentication-local'); const jwt = require('feathers-authentication-jwt'); +const path = require('path'); -function customizeJWTPayload() { - return function(hook) { +function customizeJWTPayload () { + return function (hook) { hook.data.payload = { id: hook.params.user.id }; @@ -32,7 +31,7 @@ app.configure(rest()) .configure(local()) .configure(jwt()) .use('/users', memory()) - .use('/', feathers.static(__dirname + '/public')) + .use('/', feathers.static(path.join(__dirname, '/public'))) .use(errorHandler()); app.service('authentication').hooks({ diff --git a/example/primus-client.js b/example/primus-client.js index c2cf890..fcd2758 100644 --- a/example/primus-client.js +++ b/example/primus-client.js @@ -45,6 +45,6 @@ client.authenticate({ client.set('user', user); console.log('User', client.get('user')); }) -.catch(function(error){ +.catch(function (error) { console.error('Error authenticating!', error); -}); \ No newline at end of file +}); diff --git a/example/rest-client.js b/example/rest-client.js index bb51a80..8467855 100644 --- a/example/rest-client.js +++ b/example/rest-client.js @@ -2,7 +2,7 @@ // Most of the code is the same for the browser with the exception // of how modules are imported and configured. It depends on how you choose // to load them. Refer to the client section of docs.feathersjs.com for more detail. -// +// const feathers = require('feathers/client'); const rest = require('feathers-rest/client'); const superagent = require('superagent'); @@ -33,6 +33,6 @@ client.authenticate({ client.set('user', user); console.log('User', client.get('user')); }) -.catch(function(error){ +.catch(function (error) { console.error('Error authenticating!', error); -}); \ No newline at end of file +}); diff --git a/example/socketio-client.js b/example/socketio-client.js index 10d0a9e..aafe53a 100644 --- a/example/socketio-client.js +++ b/example/socketio-client.js @@ -34,6 +34,6 @@ client.authenticate({ client.set('user', user); console.log('User', client.get('user')); }) -.catch(function(error){ +.catch(function (error) { console.error('Error authenticating!', error); -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index 73197fd..b01cfc0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "changelog": "github_changelog_generator && git add CHANGELOG.md && git commit -am \"Updating changelog\"", "compile": "rimraf lib/ && babel -d lib/ src/", "watch": "babel --watch -d lib/ src/", - "lint": "semistandard src/**/*.js test/**/*.js --fix", + "lint": "semistandard --fix", "mocha": "mocha --opts mocha.opts", "coverage": "istanbul cover _mocha -- --opts mocha.opts", "test": "npm run compile && npm run lint && npm run coverage", diff --git a/src/index.js b/src/index.js index 8fb15b4..6c293e9 100644 --- a/src/index.js +++ b/src/index.js @@ -5,13 +5,13 @@ const defaults = { header: 'authorization', cookie: 'feathers-jwt', storageKey: 'feathers-jwt', - jwtStrategy: 'jwt', + jwtStrategy: 'jwt', path: '/authentication', entity: 'user', service: 'users' }; -export default function init(config = {}) { +export default function init (config = {}) { const options = Object.assign({}, defaults, config); return function () { @@ -41,4 +41,4 @@ export default function init(config = {}) { }; } -init.defaults = defaults; \ No newline at end of file +init.defaults = defaults; diff --git a/src/passport.js b/src/passport.js index 9864759..ad6b6c0 100644 --- a/src/passport.js +++ b/src/passport.js @@ -9,7 +9,7 @@ export default class Passport { if (app.passport) { throw new Error('You have already registered authentication on this client app instance. You only need to do it once.'); } - + this.options = options; this.app = app; this.storage = app.get('storage') || this.getStorage(options.storage); @@ -22,7 +22,7 @@ export default class Passport { this.setupSocketListeners(); } - setupSocketListeners() { + setupSocketListeners () { const app = this.app; const socket = app.io || app.primus; const emit = app.io ? 'emit' : 'send'; @@ -40,7 +40,7 @@ export default class Passport { if (socket.authenticated) { const data = { strategy: this.options.jwtStrategy, - accessToken: app.get('accessToken'), + accessToken: app.get('accessToken') }; this.authenticateSocket(data, socket, emit) .then(this.setJWT) @@ -61,7 +61,7 @@ export default class Passport { if (socket.authenticated) { const data = { strategy: this.options.jwtStrategy, - accessToken: app.get('accessToken'), + accessToken: app.get('accessToken') }; this.authenticateSocket(data, socket, emit) @@ -93,7 +93,7 @@ export default class Passport { debug('Socket already connected'); return Promise.resolve(socket); } - + return new Promise((resolve, reject) => { const connected = app.primus ? 'open' : 'connect'; const disconnect = app.io ? 'disconnect' : 'end'; @@ -233,7 +233,7 @@ export default class Passport { try { let payload = decode(token); - + if (this.payloadIsValid(payload)) { return Promise.resolve(payload); } diff --git a/test/index.test.js b/test/index.test.js index 1586169..f2ea980 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -47,4 +47,4 @@ describe('Feathers Authentication Client', () => { expect(client.passport.options.service).to.equal('users'); }); }); -}); \ No newline at end of file +});