ducky/web
2015-07-07
Parent:275a83e4c02e
ducky/web/src/models/me.js
Remove local-storage wrapper, minor updates to Me model. No longer use our local-storage helper (remove it entirely), as we're no longer going to be a Chrome app. So let's just always rely on localStorage. Update our Me URL to use the nginx-fronted URL. Add an email property to our Me model, to keep track of the email we logged in with. This is mostly used for setting up our subscription, and should be deprecated in the future.
1.1 --- a/src/models/me.js Tue Jul 07 21:21:28 2015 -0400 1.2 +++ b/src/models/me.js Tue Jul 07 21:25:49 2015 -0400 1.3 @@ -4,11 +4,10 @@ 1.4 import config from '../config' 1.5 import isObject from 'lodash.isobject' 1.6 import jwtDecode from 'jwt-decode' 1.7 -import localStore from '../helpers/local-storage' 1.8 import debounce from 'lodash.debounce' 1.9 1.10 export default Model.extend({ 1.11 - url: config.urlBase + '/token', 1.12 + url: config.urlBase + '/auth/token', 1.13 ajaxConfig: { 1.14 headers: { 1.15 'Content-Type': 'application/x-www-form-urlencoded', 1.16 @@ -22,6 +21,7 @@ 1.17 expires_in: 'int', 1.18 token_created: 'date', 1.19 profileID: 'string', 1.20 + email: 'string', 1.21 }, 1.22 1.23 profile() { 1.24 @@ -60,6 +60,7 @@ 1.25 'username': email, 1.26 'password': password, 1.27 'grant_type': 'password', 1.28 + 'scope': 'subscriptions', 1.29 }), 1.30 } 1.31 let moc = this 1.32 @@ -75,6 +76,7 @@ 1.33 } 1.34 const token = jwtDecode(moc.access_token) 1.35 moc.profileID = token.sub 1.36 + moc.email = email 1.37 moc.trigger('sync', moc, resp, options) 1.38 } 1.39 options.error = function(resp) { 1.40 @@ -85,24 +87,21 @@ 1.41 1.42 writeToCache () { 1.43 const data = JSON.stringify(this) 1.44 - localStore.set('me', data) 1.45 + localStorage.setItem('me', data) 1.46 }, 1.47 1.48 load () { 1.49 let moc = this 1.50 - localStore.get('me').catch((err) => { 1.51 - console.error(err) 1.52 - }).then((resp) => { 1.53 - if (resp) { 1.54 - const loaded = this.parse(JSON.parse(resp)) 1.55 - moc.set(loaded, {silent: true}) 1.56 - } 1.57 - }) 1.58 + const resp = localStorage.getItem('me') 1.59 + if (resp) { 1.60 + const loaded = this.parse(JSON.parse(resp)) 1.61 + moc.set(loaded, {silent: true}) 1.62 + } 1.63 return this 1.64 }, 1.65 1.66 logout () { 1.67 - localStore.remove('me') 1.68 + localStorage.removeItem('me') 1.69 }, 1.70 1.71 })