
前后端分离测试,本地 POST 后台登录正常,刷新浏览器后 Auth::check() 仍是未登录状态。请问想要登录状态也能保存需要怎么设置?
跨域已设置
$response->header('Access-Control-Allow-Origin', '*'); $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN'); $response->header('Access-Control-Expose-Headers', 'Authorization, authenticated'); $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS'); $response->header('Access-Control-Allow-Credentials', 'true'); 1 agdhole Aug 6, 2020 前后端分离为什么不用 sanctum |
3 agdhole @xuncanzhe #2 应该不支持,而且现在 5.x 有重大的 cookie 漏洞,补丁还未发出 https://learnku.com/laravel/t/47887 |
4 lybcyd Aug 6, 2020 Access-Control-Allow-Credentials 设置为 true 的时候,Access-Control-Allow-Origin 不能用*,要设置成具体的地址 |
6 xuncanzhe OP @agdhole 再请教一个问题,laravel sanctum 如何从前端传来的 token 来获取用户信息?网上只有配置说明,没找到这个相关的。 |
7 agdhole Aug 14, 2020 @xuncanzhe #6 中文文档 https://learnku.com/docs/laravel/7.x/sanctum 前端在头把 Authorization 发过去,然后后端用 createToken 方法就行了 |
8 agdhole Aug 14, 2020 @xuncanzhe #6 获取用户信息可以用 $request->user(); 或者 auth()->user() https://stackoverflow.com/questions/62941992/getting-user-data-with-laravel-sanctum |