Reputation: 2833
I'm working on a Backbone app, which should serve several users.
I use Spring and it's security module in the back end and it uses basic authentication to allow access per url patterns.
So suppose there are two users, Jack and Joe and a resource called "item". Neither can see each other's items because of the http authentication. Let's say the url's are:
How do I identify the user in Backbone? Is there some smart way to do this or should I just pick the user name from the http headers and inject it to the url?
Upvotes: 2
Views: 237
Reputation: 5263
Backbone natively uses IDs for REST calls during sync(). All you need to do now is give custom URLs to models:
var Item = Backbone.Model.extend({
url: function() {
return '/users/'+this.get('name')+'/item';
}
});
Although in this scenario you will have to already have the User model loaded before you can call sync() on it, e.g. via adding them via Collection from a URL like '/users/'.
Upvotes: 1