diff --git a/lib/hooks/auth.coffee b/lib/hooks/auth.coffee new file mode 100644 index 00000000..1a80affa --- /dev/null +++ b/lib/hooks/auth.coffee @@ -0,0 +1,10 @@ +auth = require('../auth/auth') +messages = require('../messages/messages') + +exports.failIfNotLoggedIn = (fn) -> + return -> + auth.isLoggedIn (isLoggedIn) -> + if not isLoggedIn + throw new Error(messages.errors.loginRequired) + + fn.apply(null, arguments)