From 14bacbc4a487065b1b302d2593ea6b33cdca9166 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 14 Nov 2014 14:28:58 -0400 Subject: [PATCH] Make token fs based --- lib/token/token.coffee | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/token/token.coffee b/lib/token/token.coffee index ccd61081..f643ea52 100644 --- a/lib/token/token.coffee +++ b/lib/token/token.coffee @@ -1,18 +1,20 @@ # TODO: Persist token in a secure manner data = require('../data/data') -token = null +TOKEN_KEY = 'token' exports.saveToken = (newToken, callback) -> - token = newToken - return callback(null, token) + data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback) exports.hasToken = (callback) -> - return callback(token?) + data.has(TOKEN_KEY, callback) exports.getToken = (callback) -> - return callback(null, token or undefined) + data.get(TOKEN_KEY, encoding: 'utf8', callback) exports.clearToken = (callback) -> - token = null - return callback?(null) + data.has TOKEN_KEY, (hasToken) -> + if hasToken + return data.remove(TOKEN_KEY, callback) + else + return callback?()