From 0be010bb499e04d47305a7623e4577fded501d5c Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 30 Sep 2014 01:05:01 -0700 Subject: [PATCH] storing token in localStorage --- server/app/scripts/app.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/server/app/scripts/app.js b/server/app/scripts/app.js index c47b68ff..1f473808 100644 --- a/server/app/scripts/app.js +++ b/server/app/scripts/app.js @@ -5,6 +5,22 @@ var app = angular.module('app', [ 'ui.filters' ]); +// First, parse the query string +var params = {}, queryString = location.hash.substring(1), + regex = /([^&=]+)=([^&]*)/g, m; +while (m = regex.exec(queryString)) { + params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]); +} + + +// if the user is authenticated we should add Basic +// auth token to each request. +if (params.access_token) { + localStorage.setItem("access_token", params.access_token); + history.replaceState({}, document.title, location.pathname); +} + + app.config(['$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) { $routeProvider.when('/', { @@ -141,21 +157,7 @@ app.config(['$routeProvider', '$locationProvider', '$httpProvider', function($ro // use the HTML5 History API $locationProvider.html5Mode(true); - // First, parse the query string - var params = {}, queryString = location.hash.substring(1), - regex = /([^&=]+)=([^&]*)/g, m; - while (m = regex.exec(queryString)) { - params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]); - } - - - // if the user is authenticated we should add Basic - // auth token to each request. - if (params.access_token) { - $httpProvider.defaults.headers.common.Authorization = 'Bearer '+params.access_token; - window.history.replaceState( {} , document.title, '/sync' ); - } - + $httpProvider.defaults.headers.common.Authorization = 'Bearer '+localStorage.getItem('access_token'); $httpProvider.interceptors.push(function($q, $location) { return {