1

我正在使用 Nuxt 构建一个项目,并尝试使用@nuxtjs/axiosand实现身份验证@nuxtjs/auth。当我尝试登录时,该 url 不会指向代理中的内容。

我期望它会去 ex.http://blabla.com,但它只是去 http://localhost:3000

我的.env

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

这是我的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" },
        }
      }
    }
  },

我认为问题出在了@nuxt/auth,但我不知道我上面的代码是否正确。

4

0 回答 0