Laravel sanctum and Vue-JS SPA: Unterschied zwischen den Versionen

Aus Froggis Wissenssammlung
Wechseln zu:Navigation, Suche
K (Froggi verschob die Seite Laravel sanctum and Vue-JS nach Laravel sanctum and Vue-JS SPA, ohne dabei eine Weiterleitung anzulegen)
Zeile 1: Zeile 1:
=== 1. Install laravel sanctum ===
+
===1. Install laravel sanctum===
 
You may install Laravel Sanctum via Composer:
 
You may install Laravel Sanctum via Composer:
 
  <code>composer require laravel/sanctum</code>
 
  <code>composer require laravel/sanctum</code>
Next, you should publish the Sanctum configuration and migration files using the <code>vendor:publish</code> Artisan command. The <code>sanctum</code> configuration file will be placed in your <code>config</code> directory:
+
Now follow the instructions from https://laravel.com/docs/7.x/sanctum#installation to complete the installation. Especially look at the configuration.
<code>php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"</code>
+
 
Finally, you should run your database migrations. Sanctum will create one database table in which to store API tokens:
+
=== 2. Use it to authenticate a user ===
<code>php artisan migrate</code>
+
As described in the official docs do:
Next, if you plan to utilize Sanctum to authenticate an SPA, you should add Sanctum's middleware to your <code>api</code> middleware group within your <code>app/Http/Kernel.php</code> file:
+
 
<code>use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
+
 
+
<code>axios.get('/sanctum/csrf-cookie').then(response => {
'api' => [
+
    // Login...
    EnsureFrontendRequestsAreStateful::class,
+
});</code>
    'throttle:60,1',
+
 
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
+
The loginn can be the standard login of Laravels scaffolding or a custom one.
],</code>
 
This instruction is copied from: https://laravel.com/docs/7.x/sanctum#installation
 

Version vom 13. August 2020, 13:35 Uhr

1. Install laravel sanctum

You may install Laravel Sanctum via Composer:

composer require laravel/sanctum

Now follow the instructions from https://laravel.com/docs/7.x/sanctum#installation to complete the installation. Especially look at the configuration.

2. Use it to authenticate a user

As described in the official docs do:


axios.get('/sanctum/csrf-cookie').then(response => {

   // Login...

});

The loginn can be the standard login of Laravels scaffolding or a custom one.