Perhaps use Policy-based checks, and if there is no user, then treat them as guest?
Laravel 5.1 Authorization - Guest users
Hi,
I'm using the authorization features in 5.1.11 in a package, and so far it's working great except for one thing: I need non-authenticated users to be represented as guests.
I can see that the Gate class calls a user resolver, which appears to be set somewhere in AuthServiceProvider, and as per the docs, "The Gate will automatically return false for all abilities when there is not an authenticated user..."
I know it's designed to be used on authenticated users, but I think there are definitely some cases where being able to check authentication in some way as part of authorization would be beneficial. I'm just not sure how to go about it.
It seems like I have the following options:
- Extend the Gate class to tweak the user resolution and use that in my package instead
- Register a custom user resolver than returns a guest user object if the user isn't authenticated
Any other ideas? :)
Thanks
Please or to participate in this conversation.