ahmedsaoud31 / laravel-permission-to-vuejs

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

Need to recharge page to check user permissions. #13

Closed flprblr closed 1 year ago

flprblr commented 2 years ago

Hi, first of all, thank you so much for this repo, It helped me a lot.

Actually I'm having problems usings on Jetstream/Inertia, have some menu items checking permissions like user.index to show it.

After login, I need to recharge the page to see the menu items associated with the permissions. It would help if you can guide me in any solution.

Thanks Felipe R


app.js
import './bootstrap';
import '../css/app.css';
import 'flowbite';
import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
import LaravelPermissionToVueJS from 'laravel-permission-to-vuejs';

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
        .use(LaravelPermissionToVueJS)
        .use(plugin)
        .use(ZiggyVue, Ziggy)
        .mount(el);
    },
});

app.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title inertia>{{ config('app.name', 'Laravel') }}</title>
        <script type="text/javascript">
            window.Laravel = {
                csrfToken: "{{ csrf_token() }}",
                jsPermissions: {!! auth()->check()?auth()->user()->jsPermissions():0 !!}
            }
        </script>
        @routes
        @vite('resources/js/app.js')
        @inertiaHead
    </head>
    <body class="font-sans antialiased">
        @inertia
    </body>
</html>

AppLayout.vue
<JetNavLink v-if="can('user.index')" :href="route('user.index')" :active="route().current('user.index')">
    Users
</JetNavLink>
ahmedsaoud31 commented 2 years ago

Thanks ❤️ Felipe, See this issue: https://github.com/ahmedsaoud31/laravel-permission-to-vuejs/issues/4