redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

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

Open rwilliams3088 opened this issue 11 months ago • 0 comments

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?

rwilliams3088 avatar Mar 21 '24 19:03 rwilliams3088