Make token fs based

This commit is contained in:
Juan Cruz Viotti 2014-11-14 14:28:58 -04:00
parent 175e48d8ca
commit 14bacbc4a4

View File

@ -1,18 +1,20 @@
# TODO: Persist token in a secure manner # TODO: Persist token in a secure manner
data = require('../data/data') data = require('../data/data')
token = null TOKEN_KEY = 'token'
exports.saveToken = (newToken, callback) -> exports.saveToken = (newToken, callback) ->
token = newToken data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback)
return callback(null, token)
exports.hasToken = (callback) -> exports.hasToken = (callback) ->
return callback(token?) data.has(TOKEN_KEY, callback)
exports.getToken = (callback) -> exports.getToken = (callback) ->
return callback(null, token or undefined) data.get(TOKEN_KEY, encoding: 'utf8', callback)
exports.clearToken = (callback) -> exports.clearToken = (callback) ->
token = null data.has TOKEN_KEY, (hasToken) ->
return callback?(null) if hasToken
return data.remove(TOKEN_KEY, callback)
else
return callback?()