[Vuejs]-Cannot get cookie data in Vue.js and Laravel application

0๐Ÿ‘

โœ…

By default Laravel does not have the middleware required for cookies on any api route.

Usually APIs are stateless and therefore do not use cookies.

You can however, enable this functionality by adding the middleware \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class to the api group in Http\Kernel.php

 protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        // \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
        \App\Http\Middleware\NoSuperUserOnFrontEnd::class
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, <- add this

    ],
];

Leave a comment