nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 924 forks source link

auth-module not working on live server #1667

Open tad0xe opened 2 years ago

tad0xe commented 2 years ago

i have a nuxt app which i'm using nuxt auth module authentication works fine on my local machine but when deployed on live server authentication doesn't get to work

my login component

<script>
export default {
  middleware: "auth",
  auth: "guest",
  layout: "none",
  data() {
    return {
      email: "",
      password: ""
    };
  },
  methods: {
    async onLogin() {
      try {
        this.$auth.loginWith("local", {
          data: {
            email: this.email,
            password: this.password
          }
        });
        this.$router.push("/");
      } catch (err) {
        console.log(err);
      }
    }
  }
};
</script>

sign up component i get a token after signin up


<script>
export default {
  middleware: "auth",
  auth: "guest",
  layout: "none",
  data() {
    return {
      name: "",
      email: "",
      password: ""
    };
  },
     methods: {
    async onSignup() {
      try {
        let data = {
          name: this.name,
          email: this.email,
          password: this.password
        };
        let response = await this.$axios.$post("api/auth/signup", data);
        console.log(response);
        if (response.success) {
          this.$auth.loginWith("local", {
            data: {
              email: this.email,
              password: this.password
            }
          });
          this.$router.push("/");
        }
      } catch (err) {
        console.log(err);
      }
    }
  }
};

nuxt config.js

  auth: {
    strategies: {
      local: {
        token: {
          property: "token", 
          global: true,
          required: true,
          type: "Bearer"},
          user: {
            property: "user",
            autoFetch: true
          },
        endpoints: {
          login: {
            propertyName: "token",
            login: { url: "/api/auth/login", method: "post" },
          },
          logout: true
        },
        user: { url: "/api/auth/user", method: "get" }
      }
    }
  }

error i get after i click login

Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'token' in

everything works fine on my local machine without error both login and signup but when deployed on live server authentication doesn't work

Intevel commented 2 years ago

In which versions do you have this problem? @tad0xe

tad0xe commented 2 years ago

In which versions do you have this problem? @tad0xe

Version 4.9.1

tad0xe commented 2 years ago

In which versions do you have this problem? @tad0xe

have you worked with nuxt-auth