1

I run my nuxt app inside a docker container, with the aim of building once, running many. When I run a container, I want to pass in NUXT_ENV_COMMUNITY_ID which would be different per container.

However, with the following setup, when I run my container, I get an undefined error: nuxt.config.js

auth: {
    redirect: {
      home: '/home'
    },
    strategies: {
      local: {
        endpoints: {
          login: {url: "/login", method: "post"},
          logout: {url: "/logout", method: "post"},
          // user: {url: "/user/" + process.env.NUXT_ENV_COMMUNITY_ID, method: "GET"}
        },
        token: {
          property: 'token',
          global: true,
          maxAge: 14400,
        },
        redirectUri: undefined,
      }
    },
    plugins: [{ src: '~/plugins/auth', ssr: true }],
  },
  env: {
    COMMUNITY_ID: process.env.NUXT_ENV_COMMUNITY_ID
  },
  publicRuntimeConfig: {
    communityId: process.env.NUXT_ENV_COMMUNITY_ID
  },
  privateRuntimeConfig: {
    communityId: process.env.NUXT_ENV_COMMUNITY_ID
  },

The commented out line produces /user/undefined

Auth plugin

export default function({ $auth, $config }) {
  $auth.strategies.local.options.endpoints.user = {url: "/user/" + $config.communityId, method: "GET"}
}

When I run a console.log for this.$auth.strategies.local.options.endpoints in nuxtServerInit, it prints out:

  login: {
    url: '/login',
    method: 'post'
  },
  logout: {
    url: '/logout',
    method: 'post'
  },
  user: {
    url: '/user/177',
    method: 'GET'
  }

Which is what I expect, however Nuxt tries to call api/auth/user which doesn't exist. Any advice is greatly appreciated!

Thanks!

Flinty926
  • 129
  • 2
  • 9

0 Answers0