shared data in inertia config is not coming into vue props

@ryan-clare
@ryan-clare

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.

1
Create a free account to join in on the discussion
  1. @tomgobich

    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
    1. Responding to tomgobich
      @ryan-clare

      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
      1. Responding to ryan-clare
        @tomgobich

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

        0
New Discussion
Topic