Maybe you can help me with a dillema.
I use node JS, express, passport - server side and Backbone - client side.
I am developing a book manager app.
Lets say I wanted to add a new book.
On the client side:
The Backbone router sends me to addBookView.
Here, I instantiate the following model:
define([
'underscore',
'backbone'
], function(_, Backbobe){
var BookModel = Backbone.Model.extend({
url: function(){
if (this.isNew()){
return 'http://localhost:3000/books';
} else {
return 'http://localhost:3000/books/' + this.id;
}
}
});
return BookModel;
});
The model hits the following url: http://localhost:3000/books
with a POST request.
On the server side:
I check to see if the user is autentificated.
If the user isn't logged in, the server will send a 401 response (unauthorized) and nothing will be posted to my database.
Which is pretty secure, but has a flaw... and I'm not sure if I can do anything about it:
The user, even if he isn't logged in, he will still see the view's content.
He won't be able to post anything, but he will see the actual form.
Here is what I have tried:
I tried to use an express server redirect, if the user isn't logged in:
res.redirect('/');
But, that won't work because Backbone is a single page app and I am already on the index page.
- I could do a check on the Backbone router - if the user isn't logged in, I would not allow him to reach the post page.
But, this could be easily be hacked, since (i'm not a hacker) but I believe that the routers javascript could be modified to bypass that check.
What can I do?
Any ideas?