'User Log out in nuxt with laravel sanctum after browser close

I am using laravel sanctum as auth in nuxt. Everything works fine but I couldn't hold the user logged in for a much longer time.

 // Login Code
 async submit () {
                this.$auth.loginWith('laravelSanctum', { data: this.form })
                .then(response => {
                    this.$router.push(`/`)
                })
                .catch(({response}) => {
                    this.errors = response.data.errors
                })
            }

nuxt.config.js

     strategies: {

  'laravelSanctum': {
    provider: 'laravel/sanctum',
    url: process.env.API_URL,

    cookie: {
      name: 'XSRF-TOKEN',
    },
    endpoints: {
      login: {
        url: '/login',
      },
      logout: {
        url: '/logout',
        method: 'post'
      },
      refresh: {
        url: '/refresh',
        method: 'post'
      },
      user: {
        url: '/user',
        method: 'get'
      }
    },
    withCredentials: true

  },
},

Laravel code login

    public function login(Request $request)
{
    $attr = $request->validate([
        'username' => 'required|string',
        'password' => 'required|string|min:6'
    ]);
    $remember = $request->has('remember') ? true : false;

    if (Auth::attempt($attr, $remember)) {

        $token = auth()->user()->createToken('auth_token')->plainTextToken;
        $response = [
            'user' => auth()->user(),
            'token' => $token
        ];

        return response($response);
    }
    return $this->error('Credentials not match', 401);
}

Now my problem is when the user login laravel set xhrf header for auth. and xhrf header cookie expires very soon. How can I set this xhrf cookie time for longer or any other strategy to log users for a longer period?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source