fixing fitbit
This commit is contained in:
parent
225216bc98
commit
b84b6843d8
@ -8,7 +8,7 @@ var logger = require('log4js').getLogger();
|
||||
require('sugar-date');
|
||||
|
||||
var fitbit = new Fitbit(config.fitbit);
|
||||
var tokenFile = '../fb-token.json';
|
||||
var tokenFile = '../../fb-token.json';
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
@ -112,23 +112,7 @@ app.route('/poly').get(polys);
|
||||
|
||||
|
||||
var tfile = 'fb-token.json';
|
||||
var persist = {
|
||||
read: function( filename, cb ) {
|
||||
fs.readFile( filename, { encoding: 'utf8', flag: 'r' }, function( err, data ) {
|
||||
if ( err ) return cb( err );
|
||||
try {
|
||||
var token = JSON.parse( data );
|
||||
cb( null, token );
|
||||
} catch( err ) {
|
||||
cb( err );
|
||||
}
|
||||
});
|
||||
},
|
||||
write: function( filename, token, cb ) {
|
||||
console.log( 'persisting new token:', JSON.stringify( token ) );
|
||||
fs.writeFile( filename, JSON.stringify( token ), cb );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Instanciate a fitbit client. See example config below.
|
||||
//
|
||||
@ -147,11 +131,15 @@ app.get('/fitbit', function (req, res) {
|
||||
app.get('/fitbit_auth_callback', function (req, res, next) {
|
||||
var code = req.query.code;
|
||||
fitbit.fetchToken( code, function( err, token ) {
|
||||
if ( err ) return next( err );
|
||||
if ( err ) {
|
||||
return next( err );
|
||||
}
|
||||
|
||||
// persist the token
|
||||
jsonfile.writeFile( tfile, token, function( err ) {
|
||||
if ( err ) return next( err );
|
||||
if ( err ) {
|
||||
return next( err );
|
||||
}
|
||||
res.redirect( '/fb-profile' );
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user