1

In my project, I use nuxt auth-next. To validate the current saved cookie I'm checking the following conditions in nuxtServerInit.

export const actions = {
  async nuxtServerInit({ commit }, { app }) {
    if (app.$auth.loggedIn) {
      const token = app.$auth.strategies.social.token.get()
      commit('SET_TOKEN', token)
    } else {
      await app.$auth.logout('social')
    }
  },
}

once this logout method is called, the following error will occur. enter image description here "window is not defined" error will be gone if I comment this line,

} else {
         // await app.$auth.logout('social')
        }

But in my case, I want to log out the user from the system if the token is not valid. my nuxt configuration is as below,

export default {

  loading: '~/components/loaders/Loader.vue',

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: ['~/assets/css/main.css'],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    '~/plugins/axios.js',
    '~/plugins/loader.js',
    '~/plugins/vue-tooltip.js',
    {
      src: '@/plugins/notifications.js',
      mode: 'client',
    },

    {
      src: '@/plugins/v-date-picker.js',
      mode: 'client',
    },
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/eslint
    '@nuxtjs/eslint-module',
    // https://go.nuxtjs.dev/tailwindcss
    '@nuxtjs/tailwindcss',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@nuxtjs/auth-next',
    'vue-currency-input/nuxt',
  ],

  router: {
    // middleware: ['auth', 'servey-middleware', 'routing-middleware'],
    middleware: ['auth', 'servey-middleware'],
  },

  auth: {
    redirect: {
      login: '/',
      callback: '/',
      logout: `/`,
      home: '/surveys',
    },
    strategies: {
      azureAD: {
        scheme: 'oauth2',
        endpoints: {
          authorization: `${process.env.SIGNIN_POLICY}`,
          token: `${process.env.SIGNIN_POLICY}`,
          userInfo: '/',
          logout: `${process.env.SIGNIN_POLICY}`,
        },
        token: {
          property: 'access_token',
          type: 'Bearer',
          maxAge: 1800,
        },
        refreshToken: {
          property: 'refresh_token',
          maxAge: 60 * 60 * 24 * 30,
        },
        responseType: 'code',
        grantType: 'authorization_code',
        redirectUri: `${process.env.REDIRECT_URI}`,
        logoutRedirectUri: `${process.env.LOGOUT_URL}`,
        clientId: `${process.env.CLIENT_ID}`,
        scope: ['openid'],
        autoLogout: true,
        prompt: 'login',
      },
    },
  },

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    baseURL: `${process.env.API_HOST}/api/v1/cont-mgt`,
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: ['v-date-picker', 'vue-tooltip'],
  },
}

What could be wrong here or how can I solve this problem?

Sathya Molagoda
  • 531
  • 1
  • 6
  • 17

0 Answers0