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
- I log in as
user A
- Go to the /profile page
- Refresh the page (for a server-side render)
- The asyncData() method is called to get
user A
's profile - Telescope shows the authenticated user is
user A
- 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
- I log in as
user b
- Go to the /profile page
- Refresh the page (for a server-side render)
- The asyncData() method is called to get
user B
's profile - Telescope shows the authenticated user is still
user A
- Page returns 404 - as the api request failed as the request is unauthorized. (sees it as
user A
trying to getuser 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,
}
},
},
},