From fb59994e5f17bb17237e0951b6e5140ad3d7246e Mon Sep 17 00:00:00 2001 From: Simone Duca Date: Fri, 2 Feb 2018 17:19:58 +0000 Subject: [PATCH] Experiment in token refresh. Leave logs for testing on preview. --- app/modules/auth/auth.factory.js | 25 ++++++++++++++++++++----- gulp/tasks/browserify.js | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/modules/auth/auth.factory.js b/app/modules/auth/auth.factory.js index 7db4afc..7c716e5 100644 --- a/app/modules/auth/auth.factory.js +++ b/app/modules/auth/auth.factory.js @@ -4,6 +4,7 @@ require('./auth.module.js') .factory('authFactory', authFactory); var OAuth = require('panoptes-client/lib/oauth'); +var Auth = require('panoptes-client/lib/auth'); // @ngInject function authFactory($interval, $timeout, $location, $window, localStorageService, ModalsFactory, zooAPI, zooAPIConfig, CribsheetFactory, $rootScope) { @@ -11,13 +12,27 @@ function authFactory($interval, $timeout, $location, $window, localStorageServic var factory; var _user = {}; + // 2 hrs + var timeout = 120 * 60 * 1000; + + $timeout( function() { + Auth.checkBearerToken() + .then(function (token) { + console.log('Token refreshed: ', token); + }) + .catch(function (error) { + console.log('Failed to refresh token: ', error); + factory.signOut; + }) + }, 10000); // 20 sec, just for testing. Swap with timeout variable when I get this to work + OAuth.checkCurrent() - .then(function (user) { - if (user) { - _setUserData(); - } - }); + .then(function (user) { + if (user) { + _setUserData(); + } + }); factory = { signIn: signIn, diff --git a/gulp/tasks/browserify.js b/gulp/tasks/browserify.js index 1821b5d..7f6c5f5 100644 --- a/gulp/tasks/browserify.js +++ b/gulp/tasks/browserify.js @@ -66,7 +66,7 @@ function buildScript(file) { .pipe(gulpif(createSourcemap, sourcemaps.init())) .pipe(gulpif(global.isProd, streamify( uglify({ - compress: { drop_console: true } + compress: { } // leave console.log in prod, for testing }) .on('error', handleErrors) )))