Closed b0tm1nd closed 2 years ago
You can call user permissions when you make login action in SPA by recive permissions and pass it to window.Laravel.jsPermissions variable or you can call it separately like this:
// in JS
axios.get('/get-permissions').then(
response => {
window.Laravel.jsPermissions = response.data;
}
);
// in laravel route
Route::get('/get-permissions', function () {
return auth()->check()?auth()->user()->jsPermissions():0;
});
As MrEduar pointed, window.jsPermissions will nor get updated with requests when using SPA. So in my case with Laravel/Vue SPA, I have installed and configured the module and it works, except after first login shows a blank page because of JavaScript error of cannot read permissions of null. So the dashboard have to be reloaded. And upon every next login it will remember permissions from the login when it was last reloaded. So a solution to this is to make the dashboard to be reloaded after every login. But why nothing said about this? Is there a better solution?