Skip to content

fix: Auth::user returning null Error on Guest share#2

Merged
kauffinger merged 7 commits intokauffinger:mainfrom
benatoff:main
Jun 29, 2025
Merged

fix: Auth::user returning null Error on Guest share#2
kauffinger merged 7 commits intokauffinger:mainfrom
benatoff:main

Conversation

@benatoff
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
                    />

@kauffinger
Copy link
Copy Markdown
Owner

Good catch, thanks. Added tests and simplified the gate logic & will merge now 🚀

@kauffinger kauffinger merged commit 84d2df1 into kauffinger:main Jun 29, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants