Setting req.context from auth strategy (Payload 3) #9152
akantic
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a case where the authentication is handled by another backend service. Therefore I have a custom auth strategy which calls the corresponding API to fetch the user. Once the user is found on the remote backend, I recreate the same user in Payload if it does not yet exist, just because it is required by Payload (for the /me endpoint). After the authentication, I need to use the entire user object returned by the API.
This means that I would like to store the fetched user and all other metadata to req.context from the auth strategy, but the strategy does not have access to it. Is there another way to do this or does it make sense to propose this as an improvement to Payload?
My current workaround is actually returning all that data from the stategy itself, so Payload sets that as req.user. However, types are broken in that approach, as there's no way to Type Augment req.user (as far as I've tried).
Posted already on discord with no luck.
Beta Was this translation helpful? Give feedback.
All reactions