Posted 1 month ago by
ryan-clare (@ryan-clare)
@tomgobich @ryan-clare @tomgobich

1

236

shared data in inertia config is not coming into vue props

Out of the box, the adonis inertia.js config file had this section of code:

sharedData: {
    user: (ctx) => ctx.inertia.always(() => ctx.auth.user),
},

But in my vue components, when I add user to defineProps it is undefined.

What am I missing? The documentation on the AdonisJS site doesn't go into much detail.

Join The Discussion! (3 Replies)

Please sign in or sign up for free to join in on the dicussion.

  1. Commented 28 days ago

    Hi Ryan!

    The authenticated user isn't populated until you tell AdonisJS to populate it. This can be done using the auth middleware, silent_auth middleware, or manually calling auth.check() as needed. You're most likely missing one of those.

    Note that you also need to specify a serialized type for your Lucid Models using either casting or DTOs.

    1

    Please sign in or sign up for free to reply

    1. Commented 28 days ago

      Thank you! Yes, I found from another forum that I was not using the auth middleware with my route. I added it, and now the user shows up as expected.

      1

      Please sign in or sign up for free to reply

      1. Commented 28 days ago

        Awesome! I'm glad to hear you were able to get it figured out! 😊

        0

        Please sign in or sign up for free to reply