ahmedsaoud31 / laravel-permission-to-vuejs

Laravel Permission Package To Use it in VueJs
96 stars 30 forks source link

jsPermissions not being updated unless page reloaded. #12

Closed b0tm1nd closed 2 years ago

b0tm1nd commented 2 years ago

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?

ahmedsaoud31 commented 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;
});