2014-11-25 09:37:53 -04:00
|
|
|
_ = require('lodash')
|
2014-11-26 13:02:22 -04:00
|
|
|
resin = require('../resin')
|
2014-11-18 12:36:43 -04:00
|
|
|
|
2014-11-25 09:37:53 -04:00
|
|
|
exports.failIfNotLoggedIn = (fn, onError) ->
|
2014-11-18 12:36:43 -04:00
|
|
|
return ->
|
2014-11-19 09:14:40 -04:00
|
|
|
args = arguments
|
2014-11-26 13:02:22 -04:00
|
|
|
resin.auth.isLoggedIn (isLoggedIn) ->
|
2014-11-25 09:37:53 -04:00
|
|
|
|
2014-11-18 12:36:43 -04:00
|
|
|
if not isLoggedIn
|
2014-11-26 13:35:01 -04:00
|
|
|
error = new Error('You have to log in')
|
2014-11-26 09:19:02 -04:00
|
|
|
if onError?
|
|
|
|
return onError(error)
|
|
|
|
else
|
|
|
|
throw error
|
2014-11-18 12:36:43 -04:00
|
|
|
|
2014-11-19 09:14:40 -04:00
|
|
|
fn.apply(null, args)
|