お世話になります。
Laravel SanctumのSPA認証について質問があります。
現在laravel 7とvue-cliとaxiosを用いてspa認証アプリを作成しております。
登録とログインは出来て、Auth::attemptも成功するのですが、/userにaxiosから'GET'を送ると401と非認証メッセージが返ってきます。
つまり、/userへのリクエストだけが上手く行きません
localhostで動かしており、vue-cliはlocalhost:8080で
php artisan serveはlocalhost8000で動かしております。
ドメインの設定が間違ってるのかと思い下記のステートフルドメインを8080に変えたりもしてみましたが上手くいきません。
どなたか詳しい方が居られましたらお教えください。よろしくお願いします。
.env SESSION_DOMAIN=localhost SANCTUM_STATEFUL_DOMAINS=localhost:8000
route:list +--------+----------+-----------------+------+------------------------------------------------------------+-------------------------------------------------------------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+-----------------+------+------------------------------------------------------------+-------------------------------------------------------------------+ | | GET|HEAD | / | | Closure | App\Http\Middleware\EncryptCookies | | | | | | | Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse | | | | | | | Illuminate\Session\Middleware\StartSession | | | | | | | Illuminate\View\Middleware\ShareErrorsFromSession | | | | | | | App\Http\Middleware\VerifyCsrfToken | | | | | | | Illuminate\Routing\Middleware\SubstituteBindings | | | GET|HEAD | api/csrf-cookie | | Laravel\Sanctum\Http\Controllers\CsrfCookieController@show | App\Http\Middleware\EncryptCookies | | | | | | | Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse | | | | | | | Illuminate\Session\Middleware\StartSession | | | | | | | Illuminate\View\Middleware\ShareErrorsFromSession | | | | | | | App\Http\Middleware\VerifyCsrfToken | | | | | | | Illuminate\Routing\Middleware\SubstituteBindings | | | POST | api/login | | App\Http\Controllers\LoginController@login | Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful | | | | | | | Illuminate\Routing\Middleware\ThrottleRequests:60,1 | | | | | | | Illuminate\Routing\Middleware\SubstituteBindings | | | POST | api/logout | | App\Http\Controllers\LoginController@logout | Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful | | | | | | | Illuminate\Routing\Middleware\ThrottleRequests:60,1 | | | | | | | Illuminate\Routing\Middleware\SubstituteBindings | | | POST | api/register | | App\Http\Controllers\RegisterController@register | Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful | | | | | | | Illuminate\Routing\Middleware\ThrottleRequests:60,1 | | | | | | | Illuminate\Routing\Middleware\SubstituteBindings | | | GET|HEAD | api/user | | Closure | Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful | | | | | | | App\Http\Middleware\Authenticate:sanctum | | | | | | | Illuminate\Routing\Middleware\ThrottleRequests:60,1 | | | | | | | Illuminate\Routing\Middleware\SubstituteBindings | +--------+----------+-----------------+------+------------------------------------------------------------+-------------------------------------------------------------------+
```axios import axios from "axios"; let axs = axios.create({ baseURL: "http://localhost:8000/api" }); axs.defaults.withCredentials=true; export default axs;