diff --git a/lib/hooks/auth.coffee b/lib/hooks/auth.coffee index ee90589a..2c1c7790 100644 --- a/lib/hooks/auth.coffee +++ b/lib/hooks/auth.coffee @@ -9,6 +9,9 @@ exports.failIfNotLoggedIn = (fn, onError) -> if not isLoggedIn error = new Error(messages.errors.loginRequired) - return onError?(error) or throw error + if onError? + return onError(error) + else + throw error fn.apply(null, args) diff --git a/lib/hooks/auth.spec.coffee b/lib/hooks/auth.spec.coffee index 6349af63..c9088a54 100644 --- a/lib/hooks/auth.spec.coffee +++ b/lib/hooks/auth.spec.coffee @@ -4,6 +4,7 @@ sinon = require('sinon') expect = require('chai').expect config = require('../config') auth = require('../auth/auth') +data = require('../data/data') authHooks = require('./auth') johnDoeFixture = require('../../tests/fixtures/johndoe') mock = require('../../tests/utils/mock') @@ -18,6 +19,13 @@ describe 'Auth Hooks:', -> after -> mock.connection.restore() + beforeEach (done) -> + mock.fs.init() + data.prefix.set(config.dataPrefix, done) + + afterEach -> + mock.fs.restore() + describe 'if not logged in', -> beforeEach (done) ->