CORS issues with local development setup Laravel Sanctum with Vue3 cli
vue app created with vue cli.
axios.create({
baseURL: process.env.VUE_APP_API_URL,
withCredentials: true
});
.env
VUE_APP_API_URL="https://api.yourdomain.test/"
package.json
{
"serve": "vue-cli-service serve --host app.yourdomain.test --https",
}
yarn serve
Laravel 8 + Laravel sanctum
cd api.yourdomain
valet link
valet secure
.env
SANCTUM_STATEFUL_DOMAINS="app.yourdomain.test:8080"
SESSION_DOMAIN=".yourdomain.test"
SESSION_DRIVER=database
SESSION_LIFETIME=120
config/cors.php
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'supports_credentials' => true,
logout route
public function logout(Request $request)
{
Auth::guard('web')->logout();
$request->session()->flush();
$request->session()->invalidate();
$request->session()->regenerateToken();
return response()->json(['message' => 'Successfully logged out'], 200);
}
session table
php artisan session:table
php artisan migrate