4

Im trying to login from my nuxt app to my laravel sanctum back end but when I try to submit my form it throws an error

Login.vue

<script>
  export default {
    data() {
      return {
       form: {
            email: '',
            password: ''
            },
        errors: {}
      };
    },
    methods: {
        async login () {
            await this.$axios.$get('/sanctum/csrf-cookie');
            await this.$auth.loginWith('local', { data: this.form })
            .then(response => {
               
             this.$router.push('/')
             
                console.log(user);
            })
            .catch(({response}) => {
                console.log(response.data.errors);
                this.errors = response.data.errors
            })
        }
    },
  };
</script>
nuxt.config.js

 // Modules (https://go.nuxtjs.dev/config-modules)
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@nuxtjs/auth-next',
    // https://go.nuxtjs.dev/pwa
    '@nuxtjs/pwa',
  ],

  // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  axios: {
    baseURL: 'http://localhost:8000', // Used as fallback if no runtime config is provided
    credentials: true,
  },
  auth: {
  redirect: {
    login: '/login',
    logout: '/',
    callback: '/login',
    home: '/'
  },
  strategies: {
    local: {
      endpoints: {
        login: { url: '/login', method: 'post', propertyName: false },
        user: { url: '/api/user', method: 'get', propertyName: false }
      },
      tokenRequired: false,
      tokenType: false
    }
  },
  localStorage: false
},

Error : Console error

But when I try to fetch the endpoint in console it works fine response

It looks like this is problem is from a nuxt-auth-next module or maybe I miss something :(

  • 1
    For those who find this page first: https://github.com/nuxt-community/auth-module/issues/945 – jetlej Dec 21 '20 at 23:58

0 Answers0