I have been hearing a lot of buzz about SPAs, so I thought let's give it a shot and I started working on an SPA project with Laravel+Vue.
I started with making some CRUDs with the help of axios and vue-router. Everything worked out great, until I needed to authorize users and make decisions based on their roles. I realized that now that I don't have the advantage of server-side rendering (blade directives) I would have to work on the vue side to manage the roles/permissions etc. But I don't know how I can approach that... What are the best practices... Are there any gotchas to be aware of... etc. etc.
So I started my research and what I gathered from here, there, and there is that I would have to store the data in a JS object or localStorage in order to perform something like this:
<p v-if="Laravel.user.role == 'admin'"> Confidential Data </p>
<p v-else> Unimportant Information </p>
But what if the user who is actually not an admin, but a moderator, executes this Laravel.user.role.push('admin')
in the console? Wouldn't that sensitive data be exposed to him?
Also the localStorage is available with this: localStorage.getItem('user.role')
So what is/are the secure/standard/most common way(s) of handling situations like this?
<p v-if="Laravel.user.role == 'admin'"> Confidential Data </p>
will be compiled into javascript, thus every user can see it if they put effort into it, what you should to is do an api call in the component that fetches the 'confedential data' from an api endpoint only an admin can access – Omniscient