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

[4.x] Fix $authenticatedUser error with third-party addon events #9490

Merged
merged 2 commits into from Feb 9, 2024

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Feb 8, 2024

This pull request sets the $authenticatedUser property to null on our base Event class to prevent $authenticatedUser must not be accessed before initialization errors.

This error mostly seems to be happening for addons with their own events, which extend our base Event. It also only happens when they're dispatching events with Laravel's event method, rather than the ::dispatch static method we normally use in Core.

Fixes riasvdv/statamic-redirect#163.

Related Discord conversation: https://discord.com/channels/489818810157891584/1153390699161587823/1204384286052978689

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

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

The type is good to have. Can't we just add = null to the property instead?

@duncanmcclean duncanmcclean changed the title [4.x] Remove type from Event class to prevent authenticatedUser error [4.x] Fix $authenticatedUser error with third-party addon events Feb 9, 2024
@duncanmcclean
Copy link
Member Author

The type is good to have. Can't we just add = null to the property instead?

Done!

@jasonvarga jasonvarga merged commit 7195658 into 4.x Feb 9, 2024
39 checks passed
@jasonvarga jasonvarga deleted the remove-typehint-to-prevent-authenticated-user-error branch February 9, 2024 15:41
JohnathonKoster pushed a commit to JohnathonKoster/cms that referenced this pull request Feb 18, 2024
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.

Server Error on save
2 participants