Is it possible to access the authenticated user in ResourceMetadataCollectionFactory? #5069
Replies: 1 comment
-
I think it's possible but you need to be called after the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a project where I have dynamic serialization groups.
These groups are generated based on the current authenticated user role, so I can easily manage, on a property level, what a role can or cannot access.
Something like this:
This has at least two side-effects that I'm aware of:
So... I wanted to fix that and I tried another approach, that I found in SymfonyCasts, that is to decorate the ResourceMetadataCollectionFactory (link is still for v2, but I'm using v3 here).
Unfortunately, it seems that is not possible to get the authenticated user at this point, because if I do the following, the user is always
null
:Still, I hardcoded the role to see if it would actually work, and it seems so.
If I do something like the following, both the schemas and the assert seem to work correctly (according to my tests, not sure if it has other side-effects besides having a lots of new schemas per entity/group in the docs):
All this just to ask: is it possible to get the authenticated user in the ResourceMetadataCollectionFactory or have I reached a dead end?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions