Skip to content

Commit

Permalink
Merge pull request #115 from ccummings/401-error-with-no-token
Browse files Browse the repository at this point in the history
client should return a 401 error code when no token is provided
  • Loading branch information
ekryski authored and daffl committed Aug 29, 2018
1 parent ce8333d commit f7ca483
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/authentication/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as hooks from './hooks';
import { connected, authenticateSocket, getJWT, getStorage } from './utils';
import errors from 'feathers-errors';

const defaults = {
tokenKey: 'feathers-jwt',
Expand All @@ -25,7 +26,7 @@ export default function(opts = {}) {
if (!options.type) {
getOptions = getJWT(config.tokenKey, this.get('storage')).then(token => {
if (!token) {
return Promise.reject(new Error(`Could not find stored JWT and no authentication type was given`));
return Promise.reject(new errors.NotAuthenticated(`Could not find stored JWT and no authentication type was given`));
}

return { type: 'token', token };
Expand Down
1 change: 1 addition & 0 deletions packages/authentication/test/client/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const setupTests = initApp => {
.then(() => done(new Error('Should never get here')))
.catch(error => {
assert.equal(error.message, 'Could not find stored JWT and no authentication type was given');
assert.equal(error.code, 401);
done();
});
});
Expand Down

0 comments on commit f7ca483

Please # to comment.