Nuxt Auth using different prefixes for axios calls depending on server-side or client-side call #1508
Replies: 2 comments
-
I finally found the solution myself. It has to do with how nuxt/axios works differently server-sider and client side when using the proxy module. The solution was to pass the following env-variables to the Nuxt build:
|
Beta Was this translation helpful? Give feedback.
-
Hi. I'm having the exact same issue and it's driving me nuts. I can't get it to work. I'm sure I've already tried every settings permutation possible but it just won't do it. We've had project settings like this for quite some time
And it works fine. |
Beta Was this translation helpful? Give feedback.
-
In my project, I am using nuxt/auth, nuxt/proxy and nuxt/axios. My Nuxt App lives on localhost:8080 while my API is located at localhost:5000. My API generates a session and sends a http-only cookie to the frontend.
I got everything working fine. Registering, logging in ... Only on reload the app kept on logging me out. When I checked the network requests, I figured that – on reload – the Nuxt server-side was trying to make a GET request to my API's users route that I specified in the auth config. But it prefixed it with '/api'! So the final url looked like this: /api/api/v1/me.
So I deleted the '/api' from my auth.endpoints.users config. And it worked. BUT: When I am calling this.$auth.fetchUser() on the client, the API call looks as follows: /v1/me 🤯.
Am I missing something here? Or is this a bug with the Auth module? Appreciate your help.
The are my auth, proxy and axios configs in nuxt.config.js:
Beta Was this translation helpful? Give feedback.
All reactions