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

[Security] Add example to fetch User with CurrentUser attribute #18005

Open
wants to merge 1 commit into
base: 6.2
Choose a base branch
from

Conversation

ker0x
Copy link
Contributor

@ker0x ker0x commented Mar 6, 2023

Added an example to get the authenticated user with #[CurrentUser] attribute

@ker0x ker0x force-pushed the feature/currentuser-attribute branch from 9944c81 to be4143c Compare March 6, 2023 10:08
@OskarStark OskarStark requested a review from wouterj March 7, 2023 05:14
): Response {
// Call whatever methods you've added to your User class
// For example, if you added a getFirstName() method, you can use that.
return new Response('Well hi there '.$user->getFirstName());
Copy link
Contributor

Choose a reason for hiding this comment

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

what if $user result in being null like if someone remove the isgranted above
better force it to not null

and perhaps add other example with current user that may be null?

.. note::

The ``#[CurrentUser]`` attribute can only be used in controller arguments to
retrieve the authenticated user.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
retrieve the authenticated user.
retrieve the authenticated user if any.

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

Successfully merging this pull request may close these issues.

3 participants