0

I have integrated the nuxt/auth module with the Laravel Sanctum provider and the login works fine, the problem is when I want to remember the user.

I sent to the api a boolean parameter with the name remember and in the api the option remember is assigned well, the token is saved in the user table and the nuxt/auth module sets the cookie remember_web_59ba36addc2b2b2b2f9401580f014c7f58ea4e30989d but if I set the SESSION_LIFETIME to 5 minutes when I refresh the page after 5 minutes the user is disconnected and does not keep the session until 2027 which is the date assigned to the cookie, I attach an image with the dates of the cookies.

nuxt.config.js

    auth: {
    strategies: {
      'laravelSanctum': {
        provider: 'laravel/sanctum',
        url: process.env.BASE_URL
      },
    }
  },

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    baseUrl: process.env.BASE_URL,
    credentials: true
  },

And on the login page

this.$auth.loginWith('laravelSanctum', {
   data: this.form
})

The cookies with the times enter image description here

IvanG11
  • 92
  • 4

1 Answers1

0

in nuxt.config.js

axios: {
        baseURL: 'http://localhost/twillo-api/api'
      },
auth: {
    redirect: {
      login: '/account/login',
      callback: '/account/login',
      home: '/'
    },
    strategies: {
      local: {
        token: {
          property: 'data.accessToken',
          required: true,
          global: true,
          maxAge: 43200,
          type: 'Bearer',
          name: 'Authorization'
        },
        user: {
          property: 'user',
          autoFetch: false
        },
        endpoints: {
          login: { url: '/login', method: 'post' },
        },
        localStorage: {
          prefix: 'auth.'
        }
      }
    },
  },

And on the login page
setUniversal will store user record in cookie.

  this.$auth.loginWith('local', { data: payload })
                    .then(response => {
                      
                        if(response.data.status) {
                            this.$auth.setUser(response.data.data.userData)
                            this.$auth.$storage.setUniversal('user', response.data.data.userData)
                            this.$auth.$storage.setUniversal('loggedIn', true)
                          
                        }else {
                          this.invalidCredential= response.data.message
                        }
                    }).catch(error => {
                        this.backendErrors = error.response.data.errors
                    })
Engr Talha
  • 386
  • 2
  • 6
  • I am using the Laravel Sanctum provider which uses the cookie schema not the local one with the token, the login works fine, it's the remembering the login that doesn't work – IvanG11 Jan 25 '22 at 11:51
  • Actually, with local, you can save login user after login in nuxt auth (this.$auth.setUser(response.data.data.userData)) and then get user record by this.$auth.user_name. and setUniversal function will store user record in cookie then you can get by nuxt auth. – Engr Talha Jan 25 '22 at 17:35