From 8bdd3b697a13e2a5ff386a5b5b6de6f1d40d5051 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 18 Nov 2014 12:36:43 -0400 Subject: [PATCH] Implement authHooks module --- lib/hooks/auth.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/hooks/auth.coffee 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)