core icon indicating copy to clipboard operation
core copied to clipboard

Call to a member function hasPermissionTo() on null

Open Ibragim091986 opened this issue 2 years ago • 0 comments

Apiato Core Version

8.7.0

PHP Version

8.2

Database Driver & Version

No response

Description

https://github.com/apiato/core/blob/149282fbd6bfe54dfefc6e14d8142834b9612fab/Abstracts/Requests/Request.php?plain=1#L128-L140

This method triggers a "Call to a member function hasPermissionTo() on null" error if the middleware is removed from the Route, for example.

1

And if there is any value in the Permissions block in the Request.

2

I think the solution would be to check for the existence of $user in the closure before passing it to the anonymous function.

https://github.com/apiato/core/blob/149282fbd6bfe54dfefc6e14d8142834b9612fab/Abstracts/Requests/Request.php?plain=2#L137-L139

Steps To Reproduce

  1. Set values for checking in the Permissions block in the Request. 2
  2. Remove the middleware method from the Route if it exists. 1
  3. Pass this Request to a WebController. 3
  4. Make a request to this Route.

Ibragim091986 avatar Jan 06 '24 21:01 Ibragim091986