Add some code to wrap the Backbone.sync method, to add ?sessionId to a
url.
Showing
1 changed file
with
22 additions
and
0 deletions
... | @@ -32,6 +32,19 @@ define(function(require) { | ... | @@ -32,6 +32,19 @@ define(function(require) { |
32 | return deferred; | 32 | return deferred; |
33 | } | 33 | } |
34 | 34 | ||
35 | var authSync = function authSync(origSync, method, model, options) { | ||
36 | var args = _.toArray(arguments); | ||
37 | args.shift(); | ||
38 | var url = options.url || _.result(model, 'url'); | ||
39 | if (url) { | ||
40 | var sessionId = app.get('auth').get('sessionId'); | ||
41 | if (sessionId) { | ||
42 | options.url = url + (url.indexOf('?') == -1 ? '?' : '&') + 'sessionId=' + sessionId; | ||
43 | } | ||
44 | } | ||
45 | return origSync.apply(this, args); | ||
46 | }; | ||
47 | |||
35 | var FacebookProvider = Backbone.Model.extend({ | 48 | var FacebookProvider = Backbone.Model.extend({ |
36 | initialize: function(data, globalOptions) { | 49 | initialize: function(data, globalOptions) { |
37 | // early facebook javascript load | 50 | // early facebook javascript load |
... | @@ -255,6 +268,15 @@ define(function(require) { | ... | @@ -255,6 +268,15 @@ define(function(require) { |
255 | }, { | 268 | }, { |
256 | FacebookProvider: FacebookProvider, | 269 | FacebookProvider: FacebookProvider, |
257 | FormProvider: FormProvider, | 270 | FormProvider: FormProvider, |
271 | wrapSync: function(origSync) { | ||
272 | return function() { | ||
273 | return authSync.apply(this, [origSync].concat(_.toArray(arguments))); | ||
274 | }; | ||
275 | }, | ||
276 | syncMixin: function(Class) { | ||
277 | Class.prototype.sync = Auth.wrapSync(Class.prototype.sync); | ||
278 | return Class; | ||
279 | }, | ||
258 | }); | 280 | }); |
259 | return Auth; | 281 | return Auth; |
260 | }); | 282 | }); | ... | ... |
-
Please register or sign in to post a comment