0

guys! I have a problem with @nuxtjs/auth-next module. It's been working fine, until today. I don't know what happened to it, but it throws me an error:

TypeError: Cannot read properties of undefined (reading 'Authorization')
    at RequestHandler._requestHasAuthorizationHeader (runtime.mjs?edb1:948:1)
    at eval (runtime.mjs?edb1:925:1)
    at async LocalScheme.login (runtime.mjs?edb1:1193:1)

I understand that it can't define $auth global variable, but how can i fix it?

My request via nuxt-auth:

async userLogin() {
      try {
        let response = await this.$auth.loginWith("local", {
          data: this.form,
        });
        if (response.data.success == true) {
          this.error = null;
          this.$router.push("/dashboard");
        } else if (response.data.success == false) {
          this.error = response.data.error;
        }
        console.log(response);
      } catch (err) {
        console.log(err);
      }
    },

My nuxt.config.js:

modules: [
    ["nuxt-tailvue", { all: true }],
    "@nuxtjs/axios",
    "@nuxtjs/auth-next",
  ],

auth: {
    strategies: {
      local: {
        token: {
          required: true,
          type: "Bearer",
          property: "token",
          global: true,
        },
        user: {
          property: "user_data",
        },
        endpoints: {
          login: {
            url: `${process.env.API_LINK}/login`,
            method: "post",
            propertyName: "token",
          },
          logout: {
            url: `${process.env.API_LINK}/logout`,
            method: "post",
          },
          user: {
            url: `${process.env.API_LINK}/user`,
            method: "get",
          },
        },
      },
    },
  },

It doesn't even send request, because $auth is undefined, and it goes through catch

Please help me if you have any thoughts about it

Creoad
  • 11
  • 3

1 Answers1

0

Check in your package.json that you have axios and @nuxtjs/axios installed. Just leave @nuxtjs/axios. This solved my problem