1

I have used this instruction from inertiajs official website to share user auth data and it works fine for all pages except those who doesn't directly rendered by Inertia::render() method.

I need to access user authentication data from a layout component named <Master> but I can't!

here is my structure/heirarchy:

- Vue/
  - Pages/
    - Home/
      - Index.vue
    - Layouts/
      - Master.vue
      - Header.vue
      - Footer.vue
  - App.js 

here is my <Master> component:

<template>
    <Head>
        <title>My Title</title>
    </Head>

    <Header :user="user"/>
    <slot/>
    <Footer/>
</template>

<script>
import Header from './Header';
import Footer from './Footer';
import {Head} from '@inertiajs/inertia-vue3';

export default {
    data() {
        return {
           user: this.auth.user,
        }
    },
    props:{
        auth: Object,
    },
    components: {
        Header,
        Footer,
        Head,
    }
}
</script>

1 Answer 1

1

You can use the $page property or the usePage() hook.

<Header :user="$page.props.auth.user" />
const user = computed(() => usePage().props.value.auth.user)

If you scroll down the the link you have given you will know it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.