Auth-module: yarn generate now has errors for every route

Created on 8 Feb 2018  路  7Comments  路  Source: nuxt-community/auth-module

I have the auth module only being used in the /admin/ section of my site. After implementing it when I yarn generate I get this error for every route:

 Generate errors summary:

 ROUTE  /merchandise

  TypeError: Cannot read property 'url' of undefined

  - server-bundle.js:3999 Auth.get isAPIRequest [as isAPIRequest]
    server-bundle.js:3999:30

  - server-bundle.js:3812 module.exports.__webpack_exports__.a
    server-bundle.js:3812:13

  - server-bundle.js:1590 createApp
    server-bundle.js:1590:207

ex:

image

This bug report is available on Nuxt.js community (#c46)
bug

Most helpful comment

(Original reported bug) Will be fixed soon.

All 7 comments

+1

Seems like yarn generate --spa does manage to generate routes, but proxy for requests doesn't work.

+1

(Original reported bug) Will be fixed soon.

In case it helps, my nuxt.config.js

  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/auth',
  ],

  auth: {
    redirect: {
      login: '/admin',
      home: '/admin/videos',
    },
    endpoints: {
      user: { url: '/me', method: 'get', propertyName: 'data' },
      logout: { url: '/logout', method: 'get', propertyName: 'data' },
    },
  },
  axios: {
    credentials: true,
    init (axios, ctx) {
      axios.defaults.headers.common['Accept'] = 'application/json'
    },
    errorHandler (error, ctx) {
      if (error.response.data && error.response.data.message === 'Token has expired') {
        ctx.$axios.get('/logout').then((response) => {
          error.config.__isRetryRequest = true
          return ctx.$axios(error.config)
        })
      }
      return Promise.reject(error)
    }
  },

Dirty workaround:
In node_modules/@nuxtjs/auth/lib/templates/auth.class.js
Change all lines with this.$req and add a conditional.

Line 118:
old -> this.$req.url.indexOf(this.options.endpoints.user.url) === 0
new -> this.$req && this.$req.url.indexOf(this.options.endpoints.user.url) === 0

Line 197_
old -> : this.$req.headers.cookie
new -> : this.$req ? this.$req.headers.cookie : null

Probably this can break some funcionalities

This is fixed by latest stable release (4.0) 馃帄 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pi0 picture pi0  路  3Comments

yuwacker picture yuwacker  路  3Comments

DiegoGallegos4 picture DiegoGallegos4  路  3Comments

manniL picture manniL  路  4Comments

Amoki picture Amoki  路  3Comments