async/promises for requestOptions in RestfulProvider
See original GitHub issueIs your feature request related to a problem?
We use aws-amplify library for auth. To get the current users JWT, we call Auth.currentSession()
which is a Promise<User>
where User
contains a valid JWT (as the lib handles token refresh as well).
The problem is that RestfulProvider
’s requestOptions
does not allow for promises or async functions that return Partial<RequestInit>
.
Describe the solution you’d like
One of
-
requestOptions
supports async functions -
requestOptions
supportsPromise<Partial<RequestInit>>
type -
another alternative workaround for this issue
Describe alternatives you’ve considered
Current workaround I have in place is to store the JWT in Redux and connect the RestfulProvider to the store to get the JWT for requests.
However, this was an interim workaround and the JWT in Redux is not refreshed when the lib internally refreshes the JWT token - so we get 401’s after the first token refresh.
Additional context
Any help or feedback is appreciated as well - big thanks for improving the way I write React components 🙌
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
I’ll discuss with my team tomorrow morning and see about putting some time into it - thanks for the guidance 👍
@South-Paw For this kind of feature, a good start is probably to update the type here -> https://github.com/contiamo/restful-react/blob/master/src/Context.tsx#L21 (so you can see where typescript is complaining ^^)
And after add some unit tests over there -> https://github.com/contiamo/restful-react/blob/master/src/Get.test.tsx#L526 with a promise as
requestOptions
and see what you need to update to make the test happy 😁The logic is quite isolate, we have some
getRequestOption
functions (https://github.com/contiamo/restful-react/blob/master/src/Get.tsx#L207), logically with typescript and unit tests, you “just” have to follow the red. Don’t hesitate to open a draft in github if you need any help 😉