我的 Vuejs 应用程序没有设置 cookie 标头。我在端口 8000 上运行我的 laravel 应用程序,在端口 8080 上运行我的 vuejs 应用程序,我使用 fortify 进行身份验证。我的 vuejs 应用程序与我的 laravel 应用程序不在同一个目录中同样在 chrome 的网络选项卡中,此错误出现此设置 cookie 的尝试被阻止,因为 samesite=lax。这些是我的配置。.env
SESSION_DRIVER=cookie
SESSION_LIFETIME=120
SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=http://localhost:8080
cors.php
'paths' => ['api/*', '/sanctum/csrf-cookie','/login','/register'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
内核.php
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
Vue.js
我是 Vue 的新手,我知道这不是使用 axios 的最佳方式,但现在我只是想能够登录。
async login() {
try {
this.token = await axios.get("//localhost:8000/sanctum/csrf-cookie",{
headers: {
Accept: "application/json",
},
withCredentials: true,
});
this.result = await axios.post(
"//localhost:8000/login",
{ email: this.email, password: this.password },
{
headers: {
Accept: "application/json",
},
withCredentials: true,
}
);
} catch (error) {
console.log(error);
}
},
}
两天来,我已经阅读了关于这个问题的所有关于 stackoverflow 的帖子,但我仍然无法解决它。