2014-11-26 12:56:52 -04:00
|
|
|
data = require('../data/data')
|
2014-10-31 15:19:16 -04:00
|
|
|
|
2014-11-14 14:28:58 -04:00
|
|
|
TOKEN_KEY = 'token'
|
2014-10-31 15:19:16 -04:00
|
|
|
|
2014-11-07 14:51:54 -04:00
|
|
|
exports.saveToken = (newToken, callback) ->
|
2014-11-14 14:28:58 -04:00
|
|
|
data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback)
|
2014-10-31 15:19:16 -04:00
|
|
|
|
2014-11-07 14:51:54 -04:00
|
|
|
exports.hasToken = (callback) ->
|
2014-11-14 14:28:58 -04:00
|
|
|
data.has(TOKEN_KEY, callback)
|
2014-10-31 15:19:16 -04:00
|
|
|
|
2014-11-07 14:51:54 -04:00
|
|
|
exports.getToken = (callback) ->
|
2014-11-14 14:28:58 -04:00
|
|
|
data.get(TOKEN_KEY, encoding: 'utf8', callback)
|
2014-10-31 15:19:16 -04:00
|
|
|
|
2014-11-07 14:51:54 -04:00
|
|
|
exports.clearToken = (callback) ->
|
2014-11-14 14:28:58 -04:00
|
|
|
data.has TOKEN_KEY, (hasToken) ->
|
|
|
|
if hasToken
|
|
|
|
return data.remove(TOKEN_KEY, callback)
|
|
|
|
else
|
2014-11-14 15:50:29 -04:00
|
|
|
return callback?(null)
|