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.state.loggedIn false with cookies #1778

Closed Tlaloc-Es closed 2 years ago

Tlaloc-Es commented 2 years ago

Version

module: 5.0.0-1648802546.c9880dc nuxt: ex: 2.14.5

Nuxt configuration

mode:

Nuxt configuration

Reproduction

async signIn() {
      const succesfulLogin = await this.$auth.loginWith('cookie', {
        data: {
          email: this.user_email,
          password: this.user_password,
          remember: this.remember,
        },
      });
      if (succesfulLogin) {
        const response = succesfulLogin.data.data;
        await this.$auth.setUser({ user: response.user });
        console.log(this.$auth.loggedIn); -> False
        //await this.$auth.logout();
      }
    },

What is expected?

console.log(this.$auth.loggedIn); -> True

What is actually happening?

I get the 200 from login with the user data but console.log(this.$auth.loggedIn); is always false.

Steps to reproduce

Additional information

Checklist

Steps to reproduce

What is expected?

What is actually happening?

Performance analysis?

Tlaloc-Es commented 2 years ago

This is the status after call login: image

Tlaloc-Es commented 2 years ago

Finnaly works with the following configuration:

auth: {
    redirect: {
      login: '/login',
      logout: '/login',
      home: '/',
    },
    strategies: {
      cookie: {
        options: {
          httpOnly: true,
          path: '/',
        },
        user: {
          property: false,
          autoFetch: false,
        },
        endpoints: {
          login: { url: '/api/login', method: 'post' },
          logout: { url: '/api/logout', method: 'post' },
        },
      },
    },
  },