0

I'm a complete newbie to any sort of javascript web app stuff (I've only really done some DOM stuff and jquery for flashy effects and whatnot), and I'm having trouble wrapping my head around how to pretty much have a user login and having models only retrieving that user's things.

What I have so far (which I am sure is wrong, I just haven't found anything to show what else to do) is a user model (holds name, email and a js object with basic settings such as country), and a receipts model (it's a basic finance app) which contains basic number stuff and should have a user attribute pointing to user instance. If needed I'll post the models here (I am probably going to host it on github when I get it somewhat working.

I am thinking that I would have to have the user login initially, then all the backend responses will only contain the logged in user's records, but I am not sure if that is the best way to go about it.

Thanks heaps for any help!

Tom Brunoli
  • 3,436
  • 9
  • 36
  • 54
  • This... is really vague. You may want to rethink this question and try to ask about a more specific circumstance. – JayC Jan 11 '12 at 01:20
  • yeah I just re-read it and it doesn't really say what I was trying to convey... I might delete it and ask again more clearly – Tom Brunoli Jan 11 '12 at 01:39
  • 1
    your approach is the correct one! after they login, you have a session that you can use to limit the records to only the user that is authenticated. – Kenan Jan 11 '12 at 04:27

1 Answers1

1

Normally you will have a login formular, setting a session cookie after the user passed the right username/password. Know every time the user sends a request to your backend he pass the session cookie and your backend have to verify that the user allowed to get the data he is requesting.

In your application we first get a modle with all user relevant data, like name and a unique user id. After that we call our REST api with routes like this myApp.com/user/uniquieUserId/invoices for example.

Community
  • 1
  • 1
Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297