ducky/web
ducky/web/src/models/profile.js
Update our profile model to use our refresh helper. Update our profile model to send the correct authorization header when making requests, and if the request fails because the OAuth token has expired, try to use the refresh token to obtain a new access token, then retry the request.
| paddy@0 | 1 import Model from 'ampersand-model' |
| paddy@12 | 2 import refresh from '../helpers/oauth-refresh' |
| paddy@0 | 3 |
| paddy@0 | 4 export default Model.extend({ |
| paddy@0 | 5 props: { |
| paddy@0 | 6 'id': 'string', |
| paddy@0 | 7 'name': 'string', |
| paddy@0 | 8 'created': 'date', |
| paddy@0 | 9 'last_seen': 'date', |
| paddy@0 | 10 }, |
| paddy@12 | 11 sync: refresh.Sync, |
| paddy@12 | 12 parse (attrs) { |
| paddy@12 | 13 if (attrs.profiles && attrs.profiles.length == 1) { |
| paddy@12 | 14 attrs = attrs.profiles[0] |
| paddy@12 | 15 } |
| paddy@12 | 16 return attrs |
| paddy@12 | 17 }, |
| paddy@12 | 18 ajaxConfig () { |
| paddy@12 | 19 return { |
| paddy@12 | 20 headers: { |
| paddy@12 | 21 'Authorization': 'Bearer '+app.me.access_token, |
| paddy@12 | 22 'Accept': 'application/json', |
| paddy@12 | 23 } |
| paddy@12 | 24 } |
| paddy@12 | 25 }, |
| paddy@0 | 26 }) |