balena-cli/lib/hooks/auth.coffee
2014-11-25 09:37:53 -04:00

15 lines
348 B
CoffeeScript

_ = require('lodash')
auth = require('../auth/auth')
messages = require('../messages/messages')
exports.failIfNotLoggedIn = (fn, onError) ->
return ->
args = arguments
auth.isLoggedIn (isLoggedIn) ->
if not isLoggedIn
error = new Error(messages.errors.loginRequired)
return onError?(error) or throw error
fn.apply(null, args)