fix: Auth::user returning null Error on Guest share#2
Merged
kauffinger merged 7 commits intokauffinger:mainfrom Jun 29, 2025
Merged
fix: Auth::user returning null Error on Guest share#2kauffinger merged 7 commits intokauffinger:mainfrom
kauffinger merged 7 commits intokauffinger:mainfrom
Conversation
…re authorisation" This reverts commit e2ea362.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an error occurring on guest shares where Auth::user() returns null, causing a fatal error when calling ->can on null. Key changes include:
- Replacing Auth::user()->can() calls with Gate::authorize() in the Livewire component.
- Adjusting view templates to conditionally render controls based on authentication.
- Modifying test cases to validate guest and authenticated access scenarios.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Feature/Livewire/Chats/ShowTest.php | Updated test descriptions and added tests for guest chat access. |
| resources/views/livewire/chats/show/message-input.blade.php | Removed inline update authorization (@can) block from the message input view. |
| resources/views/livewire/chats/show.blade.php | Wrapped message input inclusion within an @auth directive. |
| app/Policies/ChatPolicy.php | Updated chat view policy to safely handle guest users. |
| app/Livewire/Chats/Show.php | Replaced Auth::user()->can() checks with Gate::authorize() to handle authorization. |
Comments suppressed due to low confidence (1)
resources/views/livewire/chats/show/message-input.blade.php:18
- [nitpick] Consider adding an inline comment to clarify that the authorization check was removed because the parent's view (@auth) and Livewire component now handle it, preventing confusion for future maintainers.
/>
Owner
|
Good catch, thanks. Added tests and simplified the gate logic & will merge now 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On guest share Auth::user() returns null and throws subsequent error since ->can cannot be called on null. Gate::allows() handles its own user identification.