https://github.com/nuxt-community/auth-module
Nuxt auth module will make a request ON SERVER SIDE and BEFORE RENDER CONTENT set variable loggenIn to appropriate value.
Nuxt auth module makes authentication request on client side and re-renders page, it leads to problems with ssr.
I don't know why, but when I build application and deploy it to production – everything works fine and I don't see any client-side requests, but only in dev mode on my laptop (osx) I have this annoying trouble – it makes my development painful. I also want to provide my project stack and difference between production machine and local. Project stack – symfony as backend api and nuxt as frontend. Symfony and database are working in docker and it's too slow (popular issue on macOS – https://github.com/docker/for-mac/issues/2707). On my production machine I'm using ubuntu, symfony and database are working without docker.
My nuxt config for auth module:
auth: {
strategies: {
local: {
endpoints: {
login: {
url: '/userapi/authenticate',
method: 'post'
},
user: {
url: '/userapi/authenticated_user',
method: 'get',
propertyName: 'email'
},
logout: {
url: '/userapi/logout',
method: 'delete'
}
},
tokenRequired: false,
tokenType: false
}
},
watchLoggedIn: false,
redirect: false
},
Request that is sent on initial loading (reload page, already has valid cookie for authentication):

Errors which I have in console:

I solved this by adding baseUrl property to my axios configuration. By default axios, which used in auth module, makes user request by url localhost:3000, because nuxt in dev mode uses port 3000. In my case I used nginx proxy in dev mode for userapi route, but my nginx listens port 3030. From client side it was OK because it was relative path, but from server side it wasn't and user request was sent to wrong endpoint.
I'm facing this issue but my api endponts are working perfectly
The always showen when using v-if with $auth.user
Most helpful comment
I solved this by adding
baseUrlproperty to my axios configuration. By default axios, which used in auth module, makes user request by urllocalhost:3000, because nuxt in dev mode uses port 3000. In my case I used nginx proxy in dev mode foruserapiroute, but my nginx listens port 3030. From client side it was OK because it was relative path, but from server side it wasn't and user request was sent to wrong endpoint.