emohammad liked this thread
Hello You should use a state manager if you need to check permissions from frontend. I'm developing an app with same stack. I'm using pinia for frontend permission checks. Ofcourse you need to check permissions on backend eitherway. How i succeed in doing it is;
export const useYetkilerStore = defineStore('yetkiler', { state: () => { const yetkiler = []; const roller = []; return { yetkiler, roller, } }, getters: { can (state) { return (yetkiadi) => { if ( state.yetkiler && state.yetkiler.indexOf(yetkiadi) !== -1 || state.roller.indexOf('admin') > -1
) {
return true;
}
return false;
}
},
any (state) {
return (yetkiler) => {
if ((state.yetkiler && state.yetkiler.filter(item => yetkiler.indexOf(item) !== -1).length) || state.roller.indexOf('admin') > -1) {
return true;
}
return false;
}
},
all (state) {
return (yetkiler) => {
if ((state.yetkiler && state.yetkiler.filter(item => yetkiler.indexOf(item) !== -1).length === yetkiler.length) || state.roller.indexOf('admin') > -1) {
return true;
}
return false;
}
},
is (state) {
return (roleadi) => {
if (state.roller && state.roller.indexOf(roleadi) !== -1) {
return true;
}
return false;
}
}
}, actions: { setYetkiler (yetkiler) { this.yetkiler = yetkiler; }, setRoller (roller) { this.roller = roller; } } }); ` yetkiler = abilities roller = roles
I'm loading permissions and roles from main layout:
setup(){ onBeforeMount(() => { yetkilerStore.setRoller(window.roles); yetkilerStore.setYetkiler(window.abilities); }) }
I'm using window object instead of something else because i want to be sure that i'm loading all permissions before anything else is mounted.
It's my first post. Be easy on me :)
@gokhansarigul have you took a look into inertia remember
feature? It suppose to do the trick without the need to use Pinia.
As i understood "Remember" feature is used for browser history features. It doesnt look like a state manager, but more like to keep form filled in case of history.back()
emohammad liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community