Hey guys, I'm working on a possible migration from...
# prisma-whats-new
i
Hey guys, I'm working on a possible migration from rest to graphql (vue <-> rest php <-> elastic into vue <-> graphcool), I was wondering about the proper way to add (as an exemple) the logged user to a type (post). In my rest API, I can check if the userId in parameter of my route is the same as the logged one (or just add the logged one to my entity/document), but I can't have a clean vision of this process in graphql, have you any guidelines about ? Thanks a lot ❤️
i
I’m not 100% sure I understand but you can access
this.props.loggedInUser
from whatever component you set the auth token and any of that component’s children
i
Sorry, my english is not as clean as my mind... The idea is just to check (server side) if the userId in my createPost mutation is the same as the one who's creating this Post (he can hack it client side to pass another one for exemple) you see what i mean ?
i
Yeah. That’s why you access
this.props.loggedInUser
. For example, you can store the user’s ID & token in
localStorage
, protect those routes, and check on the client if the user ID matches the loggedInUser ID to authorize that user to make that request
I haven’t worked much with Vue so I’m not sure if
this.props
is a convention, but the idea is still the same
i
Hmm, the problem is that this user can modify his userId in localstorage (or whatever) but keep his token and createPost with this fake id. I can't protect it.
i
That is not the easiest of things to do. 1. The user would need to really know what to do. 2. You should ensure that the userID is authorized to create a post. 3. You should validate the token to ensure he/she is logged in. 4. You should ensure that the userID is a real ID coming from the database. If not, then respond with a
401
You could also store credentials in a cookie
Instead of in local storage
i
Well, that sounds ok
(thinking...)
I'll try to make my schema. I think I'm too obsessed with security (and I want to secure everything server side). I'll come back if I can't make something secure. Thanks for your help 🙂 See you