FupingQiu / okrsw

0 stars 0 forks source link

Error in v-on handler (Promise/async): "Error: Request failed with status code 403" This action is unauthorized #30

Closed FupingQiu closed 4 years ago

FupingQiu commented 4 years ago

[Vue warn]: Error in v-on handler (Promise/async): "Error: Request failed with status code 403"

found in

---> at resources/js/pages/okrs/index.vue

at resources/js/components/Child.vue at resources/js/layouts/default.vue warn @ vue.common.dev.js?ed88:630 logError @ vue.common.dev.js?ed88:1889 globalHandleError @ vue.common.dev.js?ed88:1884 handleError @ vue.common.dev.js?ed88:1844 (anonymous) @ vue.common.dev.js?ed88:1861 Promise rejected (async) invokeWithErrorHandling @ vue.common.dev.js?ed88:1861 invoker @ vue.common.dev.js?ed88:2184 original._wrapper @ vue.common.dev.js?ed88:7537 vue.common.dev.js?ed88:1893 Error: Request failed with status code 403 at createError (createError.js?cc5a:16) at settle (settle.js?cc26:18) at XMLHttpRequest.handleLoad (xhr.js?eda7:59) F12调试模式下: 1. {data: {…}, status: 403, statusText: "Forbidden", headers: {…}, config: {…}, …} 1. config: 1. adapter: ƒ xhrAdapter(config) 2. data: "{"anObject":"","classify":3}" 3. headers: {Accept: "application/json, 4. text/plain, */*", X-Requested-With: "XMLHttpRequest", X-CSRF-TOKEN: "", Authorization: "Bearer 5. eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI…93X8MlWtOwcZ05-gVoQLuIPTxzuC8Ja40EETzYYr92v7qAzec", Accept-Language: "zh-CN", …} 6. maxContentLength: -1 7. method: "post" 8. timeout: 0 9. transformRequest: {0: ƒ} 10. transformResponse: {0: ƒ} 11. url: "/api/okrs" 12. validateStatus: ƒ validateStatus(status) 13. xsrfCookieName: "XSRF-TOKEN" 14. xsrfHeaderName: "X-XSRF-TOKEN" 15. __proto__: Object 2. data: {**message: "This 3. action is unauthorized."**, exception: "Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException", file: "E:\laragon40\www\OKRsing\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php", line: 206, trace: Array(45)} 4. headers: {cache-control: "no-cache, 5. private", connection: "keep-alive", content-type: "application/json", date: "Tue, 6. 31 Mar 2020 15:30:47 GMT", phpdebugbar-id: "X7612eeaf141d7a037fcc8fd40342cdc1", …} 7. request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …} 8. status: 403 9. statusText: "Forbidden" 10. __proto__: Object
FupingQiu commented 4 years ago

参考资料:

https://learnku.com/articles/41853

Laravel使用policy完成用户授权: https://blog.csdn.net/zhouyuqi1/article/details/77574015 1.策略类和模型关联即是在policy中编写我们的策略方法 class PostPolicy{ use HandlesAuthorization; 2.'App\Post' => 'App\Policies\PostPolicy', //注册Post的policy 3.$this->authorize('update',$post); ////////////////////策略判断

Laravel 常见错误:https://www.jianshu.com/p/dc7e490835f9 Request 文件中的false改成true public function authorize(){ return true; }

FupingQiu commented 4 years ago

经验证,处理如下操作可以fix "This action is unauthorized"问题。 Request 文件中的false改成true public function authorize(){ return true; }