You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
This line, in the Article edit view, is attempting to validate if the current User is the owner of the Article being edited. Since we're not storing the User's _id field on the client-side User object any longer, it cannot evaluate properly.
To reproduce this...
Login with a User that has created Article(s) (or create an Article after log in).
Go to an article that the user owns and you'll see that the edit & remove buttons are present
Do a hard refresh of the browser (Ctrl+F5), and you'll see the button are now gone
I know the decision to remove the _id field from the client-side User object was intentional, for security reasons. I'm unclear as to the exact implications of having the _id field; can someone shed light on that for me?
A simple, but hackish way of fixing this would be to compare the User's username field, with the Articles user.username field; which means we'd have to populate the latter on the Article object when we retrieve it from the database.
A better solution that comes to mind is to handle the validation in the controller, by retrieving the User's info from the back-end & then setting a property on the view model (vm) that specifies if they own the document. This option requires more changes than the simple solution I described above, but is probably better practice.
Something like this..
functionisArticleOwner(){// we need to load the user from the backend somehow// maybe, with a resolve User in the client route configif(user._id.toString()===article.user._id.toString()){returntrue;}else{returnfalse;}}
Any ideas?
The text was updated successfully, but these errors were encountered:
Adds a custom field named `isCurrentUserOwner` to the Article document before
it's returned to the client. This field is used to determine if the current
User should is the "owner", and should see the edit/delete controls on the
client-side when viewing a single article. This custom (ad-hoc) field is NOT
persisted to the database; it's merely attached to the document.
Added server-side route tests for verifying the ad-hoc
"isCurrentUserOwner" field is properly set on the a single Article document.
Fixesmeanjs#1146
This line, in the Article edit view, is attempting to validate if the current User is the owner of the Article being edited. Since we're not storing the User's
_id
field on the client-side User object any longer, it cannot evaluate properly.To reproduce this...
I know the decision to remove the
_id
field from the client-side User object was intentional, for security reasons. I'm unclear as to the exact implications of having the_id
field; can someone shed light on that for me?A simple, but hackish way of fixing this would be to compare the User's
username
field, with the Articlesuser.username
field; which means we'd have to populate the latter on the Article object when we retrieve it from the database.A better solution that comes to mind is to handle the validation in the controller, by retrieving the User's info from the back-end & then setting a property on the view model (
vm
) that specifies if they own the document. This option requires more changes than the simple solution I described above, but is probably better practice.Something like this..
Any ideas?
The text was updated successfully, but these errors were encountered: