无法在前端使用Laravel Sanctum来生成CSRF cookie
P粉099985373
P粉099985373 2023-08-26 19:05:10
0
1
419
<p>最近我尝试在Nuxt 3中使用Laravel Sanctum进行身份验证,但在初始的CSRF cookie握手过程中遇到了问题。问题是,在我向<code>http://localhost:8000/sanctum/csrf-cookie</code>路径发出请求后,浏览器没有设置XSRF-TOKEN cookie。我已经困在这个问题上已经一个星期了,在互联网上还没有找到解决方案。 我尝试使用Axios和Fetch API来设置XSRF-TOKEN,但没有成功。我在后端使用的是<code>http://localhost:8000</code>,前端使用的是<code>http://localhost:3000</code>。Laravel Sanctum本身工作正常,因为在Postman上测试时我收到了set-cookie头部,但浏览器没有收到。我在<code>.env</code>文件中设置了以下属性:</p> <pre class="brush:php;toolbar:false;">FRONTEND_URL=http://localhost:3000 SESSION_DOMAIN=localhost:3000 SESSION_DRIVER=cookie</pre> <p>我已经尽一切努力克服前端CORS请求的限制。我的fetch函数如下所示:</p> <pre class="brush:php;toolbar:false;">window.fetch('http://localhost:8000/sanctum/csrf-cookie', { credentials: 'include', }).then((response) =&gt; { console.log(…response.headers) })</pre> <p>我读到过将credentials设置为'include'可以解决问题,但即使这样做,我仍然无法设置XSRF-TOKEN。我尝试将credentials设置为'same-origin',但也不起作用。有人知道如何解决这个问题吗?</p>
P粉099985373
P粉099985373

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!