Laravel API Authentication: Consuming Your API With JavaScript

'web' => [
    // Other middleware...
    \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],
Axios.get('/api/user')
    .then(response => {
        console.log(response.data);
    });

Customizing The Cookie Name

/**
 * Register any authentication / authorization services.
 *
 * @return void
 */
public function boot()
{
    $this->registerPolicies();

    Passport::routes();

    Passport::cookie('custom_name');
}

CSRF Protection

Window.axios.defaults.headers.common = {
    'X-Requested-With': 'XMLHttpRequest',
};

Laravel API Authentication: Consuming Your API With JavaScript — Structure map

Clickable & Draggable!

Laravel API Authentication: Consuming Your API With JavaScript — Related pages: