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 loggedIn doesn't update after loginWith() #1428

Closed VividLemon closed 2 years ago

VividLemon commented 2 years ago

Version

module: nuxt:

Nuxt configuration

mode:

Nuxt configuration

 auth: {
    redirect: {
      callback: '/',
      home: '/',
      login: '/',
      logout: '/'
    },
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'accessToken',
          maxAge: 900000
        },
        refreshToken: {
          property: 'refreshToken',
          data: 'token',
          maxAge: 86400
        },
        user: {
          // Unused
          property: 'user',
          autoFetch: false
        },
        endpoints: {
          login: { url: '/api/auth/login', method: 'post' },
          refresh: { url: '/api/auth/refresh', method: 'post' },
          logout: { url: '/api/auth/logout', method: 'post' }
        }
      }
    }
  },

Reproduction

try {
        console.log(this.$auth)
        await this.$auth.loginWith('local', { data: { name: this.username, password: this.password } })
        console.log(this.$auth)
        this.$router.push(this.localePath('/'))
      } 

:warning: without a minimal reproduction we won't be able to look into your issue

What is expected?

this.$auth.loggedIn to be updated after loginWith method.

What is actually happening?

this.$auth.loggedIn (and the .storage object containing the same data not updating either)

Steps to reproduce

Just logging in.

Additional information

I feel like I may have overlooked something. I bug of this size couldn't have been overlooked. Values are properly updated after a manual refresh, but that defeats the point of an SPA doesn't it.

Checklist

VividLemon commented 2 years ago

My fault. Fetching user after login with refresh is required. Imo fetching the user should be optional as in some cases only the authentication jwt should suffice