1

I am building a project with Nuxt and trying to implement an authentication using @nuxtjs/axios and @nuxtjs/auth. When i'm trying to login, the url doesn't path to what in the proxy does.

what do i expect is it will going to ex.http://blabla.com, but it just going to http://localhost:3000

my .env :

baseURL=http://localhost:3000/api/
dbURL=https://something.com/db/

this is my nuxt.config.js :

modules: ['@nuxt/content', '@nuxtjs/auth-next', '@nuxtjs/axios', '@nuxtjs/proxy'],
  axios: {
    proxy: true,
    credentials: true
  },
  proxy: {
    "/db/": {
      target: process.env.dbURL,
      pathRewrite: { "^/db/": "" }
    },
    "/api/": {
      target: process.env.baseURL,
      pathRewrite: { "^/api/": "" }
    },
  },
  serverMiddleware: [
    { path: '/api', handler: '~/api/index.js' }
  ],
  auth: {
    strategies: {
      local: {
        //      scheme: "refresh",
        token: {
          property: "result.key.accessToken", //property name that the Back-end sends for you as a access token for saving on localStorage and cookie of user browser
          global: true,
          required: true,
          type: "Bearer"
        },
        user: {
          property: "user",
          autoFetch: true
        },
        refreshToken: {  // it sends request automatically when the access token expires, and its expire time has set on the Back-end and does not need to we set it here, because is useless
          property: "result.key.refreshToken", // property name that the Back-end sends for you as a refresh token for saving on localStorage and cookie of user browser
          //data: "refresh_token", // data can be used to set the name of the property you want to send in the request.
        },
        endpoints: {
          login: { url: "/db/Users/login", method: "post", },
          logout: { url: "/db/Users/logout", method: "post", data: {} },
          user: { url: "/db/Users/getUsers", method: "get" },
        }
      }
    }
  },

I was think the problem is on @nuxt/auth, but i dont know if my codes above is correct or not.

kissu
  • 40,416
  • 14
  • 65
  • 133
Nta
  • 79
  • 6
  • i'm facing the same problem too! It seems that the proxy part is just append to the actual url `http://current-url/proxypart` and fallback to an 504 Error `(ERROR [HPM] Error occurred while proxying request) [ECONNREFUSED]` – Diand Mar 25 '22 at 19:29

0 Answers0