ducky/web
ducky/web/src/models/profiles.js
Update our profiles collection to use ampersand-rest-collection. Use ampersand-rest-collection instead of ampersand-collection, so we can take advantage of the excellent "getOrFetch" function to fall back on the server when looking for a member of the collection that isn't downloaded yet. Also, use the correct Authorization header when making profile collection requests. Finally, if the profile collection requests fail due to an expired access token, use the refresh token to acquire a new access token, then retry the request.
1.1 --- a/src/models/profiles.js Tue Jun 30 01:23:04 2015 -0400 1.2 +++ b/src/models/profiles.js Tue Jun 30 01:25:20 2015 -0400 1.3 @@ -1,18 +1,25 @@ 1.4 -import Collection from 'ampersand-collection' 1.5 +import Collection from 'ampersand-rest-collection' 1.6 import Sync from 'ampersand-sync' 1.7 import Profile from './profile' 1.8 import config from '../config' 1.9 import isObject from 'lodash.isobject' 1.10 +import refresh from '../helpers/oauth-refresh' 1.11 +import app from 'ampersand-app' 1.12 1.13 export default Collection.extend({ 1.14 model: Profile, 1.15 url: config.urlBase + '/profiles', 1.16 - ajaxConfig: { 1.17 - headers: { 1.18 - 'Content-Type': 'application/json', 1.19 + ajaxConfig () { 1.20 + return { 1.21 + headers: { 1.22 + 'Authorization': 'Bearer '+app.me.access_token, 1.23 + 'Accept': 'application/json', 1.24 + } 1.25 } 1.26 }, 1.27 1.28 + sync: refresh.Sync, 1.29 + 1.30 register (email, passphrase) { 1.31 let options = { 1.32 data: JSON.stringify({