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

How to customize headers (async) on a per endpoint basis? #4290

Closed
rwilliams3088 opened this issue Mar 21, 2024 · 1 comment
Closed

How to customize headers (async) on a per endpoint basis? #4290

rwilliams3088 opened this issue Mar 21, 2024 · 1 comment

Comments

@rwilliams3088
Copy link

I am working on implementing security for my web application with AWS Cognito. I've written a little Auth API that will return an access token for a given scope, and I would like to customize my endpoints so that they automatically add the Authorization header to the request with an appropriately scoped access token.

So, for instance, my endpoint for reading the schedule would need an access token with the scope "schedules.read".

Since I may need to asynchronously fetch the accessToken if a valid one for that scope isn't cached, I can't use the headers property on the endpoint.

There is the prepareHeaders function on the baseQuery which looks promising. However, I'd need a good way to inform that function of what scopes to request for the endpoint in question. Is there mechanism to add and retrieve metadata for endpoints that could be used in prepareHeaders? Or a way to use an asynchronous function on the endpoint definition to set the headers?

@markerikson
Copy link
Collaborator

https://github.com/reduxjs/redux-toolkit/releases/tag/v2.3.0 now exposes an extraOptions field into prepareHeaders, as well as the URL arg for the current query.

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

No branches or pull requests

2 participants