question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async/promises for requestOptions in RestfulProvider

See original GitHub issue

Is 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 supports Promise<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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
South-Pawcommented, Nov 19, 2019

I’ll discuss with my team tomorrow morning and see about putting some time into it - thanks for the guidance 👍

1reaction
fabien0102commented, Nov 19, 2019

@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 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found