0

I am not entirely sure what / how this is happening but I am having an issue with my Nuxt.js (Nuxt 2 more specifically) application using Laravel Sanctum as the auth provider. The application is a sort of dashboard, which is behind a user authentication and currently just has a profile page.

Here's what is happening

  1. I log in as user A
  2. Go to the /profile page
  3. Refresh the page (for a server-side render)
  4. The asyncData() method is called to get user A's profile
  5. Telescope shows the authenticated user is user A
  6. The page loads with user A's data

Then, I log out and repeat the process as user B - but this is where the issue is

  1. I log in as user b
  2. Go to the /profile page
  3. Refresh the page (for a server-side render)
  4. The asyncData() method is called to get user B's profile
  5. Telescope shows the authenticated user is still user A
  6. Page returns 404 - as the api request failed as the request is unauthorized. (sees it as user A trying to get user B's profile data.

For some reason it's like the server side response is cached? The weird thing is that this only happens when hard refreshing (so client side navigation works), and when running the development server - this never happens once I build the application.

This is mostly giving me grief in cypress as when it comes round to logging in to the second user and going directly to the profile page (server side rendered) it fails as it comes back as 404 because the api request fails and so does my test.

Any insights or help would be greatly appreciated!

Here is my config for Axios:

auth: {
    strategies: {
        'laravelSanctum': {
            provider: 'laravel/sanctum',
            url: `${process.env.BACKEND_API_URL}/auth`,
            endpoints: {
                csrf: {
                    url: '/csrf-cookie',
                    method: 'get'
                },
                user: {
                    url: '/user',
                    method: 'get',
                    propertyName: false
                }
            },
            user: {
                autoFetch: false,
            }
        },
    },
},

0 Answers0