Auth-module: Cannot read property 'onError' of undefined

Created on 5 Mar 2018  路  5Comments  路  Source: nuxt-community/auth-module

I've tried using the snippet codes on handling error but it is returning an error. I need to catch the error when the user inputs and invalid credentials.

Here are the things I've done

  1. I created plugins/auth.js and placed this code
export default function({ $auth }) {
    $auth.onError((error, name, endpoint) => {
        console.error(name, error)
    })
}
  1. Add this code to nuxt.config.js
{
     plugins:['@/plugins/auth.js'],
}

It is returning Cannot read property 'onError' of undefined.
Thanks

This question is available on Nuxt.js community (#c63)

Most helpful comment

Works for me, could be worth double checking your plugins are declared inside the auth (rather than the regular place you setup nuxt plugins)

{
  modules: {
    '@nuxtjs/auth'
  },
  auth: {
     plugins: [ '~/plugins/auth.js' ]
  }
}

https://auth.nuxtjs.org/recipes/extend.html

All 5 comments

Hello @ikristher i had the same error with v4.0.0-rc.3. My workaround is use app param in destructuring.

Example

export default function({ app }) {
    app.$auth.onError((error, name, endpoint) => {
        console.error(name, error)
    })
}

This work fine but when I try to use $auth into vue file I got same error

 this.$auth.login({
        data: {
          username: this.username,
          password: this.password
        }
      });

Hi. With 4.0.0 you can now handle login errors.

Still have the same problem with ^4.2.0

Any fix for this ?

Works for me, could be worth double checking your plugins are declared inside the auth (rather than the regular place you setup nuxt plugins)

{
  modules: {
    '@nuxtjs/auth'
  },
  auth: {
     plugins: [ '~/plugins/auth.js' ]
  }
}

https://auth.nuxtjs.org/recipes/extend.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javialon26 picture javialon26  路  3Comments

roosht3 picture roosht3  路  3Comments

dasisyouyu picture dasisyouyu  路  3Comments

essamamdani picture essamamdani  路  3Comments

DiegoGallegos4 picture DiegoGallegos4  路  3Comments