Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy in screen #2691

Open
DarKsandr opened this issue Aug 7, 2023 · 3 comments
Open

Policy in screen #2691

DarKsandr opened this issue Aug 7, 2023 · 3 comments
Assignees
Labels

Comments

@DarKsandr
Copy link
Contributor

I wanted to use policy, but I always get 403 THIS ACTION IS UNAUTHORIZED.

Route::screen('/chat/{chat}', ChatScreen::class)
    ->can('view', 'chat')
    ->name('platform.chat');
class ChatPolicy
{
    public function view(User $user, Chat $chat): bool
    {
        return true;
    }
}

But if you use policies in the screen itself, then everything works

class ChatScreen extends Screen
{
    public function query(Chat $chat): iterable
    {
        if($chat->exists){
            $this->authorize('view', $chat);
        }
        ...
    }
...
@tabuna
Copy link
Member

tabuna commented Aug 20, 2023

To help you, please submit an issue using a template that includes the version you are using

@DarKsandr
Copy link
Contributor Author

  • Platfrom Version: 14.8.0
  • Laravel Version: 10.16.1
  • PHP Version: 8.1

@tabuna
Copy link
Member

tabuna commented Aug 28, 2023

I would like to confirm that the usage of the can method always results in a 403 error. This is due to Screen determining which method to call later than the can middleware operates.

I have discovered a hacky way to make it work in this branch: compare/auth_middleware_policy, but I am not satisfied with this solution. I am open to any suggestions or alternatives you may have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants