-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Aborting requests with expired tokens from the Authentication Middleware #1985
Comments
Instead of executing the request and then aborting it, would it make sense to just throw in the onRequest middleware in this case? In fact, the openapi-typescript/packages/openapi-fetch/src/index.js Lines 107 to 127 in 639ec45
|
@gzm0 But this would entitle that I have to try-catch every outgoing request, what if I just need to silently abort ? |
Just to add a little more context: this was a feature we talked about and delayed because we were determining how people used this library. When paired with TanStack Query, e.g., it would just add overhead. But for people who are using openapi-fetch, and only openapi-fetch, without any wrapper (as some stated), it is a useful API. A side question I have is “would adding an AbortController to every request introduce any overhead or performance concerns?” I don’t have any reason to believe it would, especially since in most scenarios, these won’t persist, will be garbage-collected, and a client should never have more than a dozen requests going at a time or so. So I think an implementation would be safe to just create an AbortController for every request. I like @darkbasic’s proposal for the API, and would accept a PR introducing that. Any additional concerns/details we have could be addressed in the PR 🙂 |
Oh and yes @gzm0 to your comment, I was interpreting this the need to silently fail without throwing an error. Expired tokens are a great case where it’s helpful to at least retry silently in the background a few times before logging the user out or displaying an error message. |
Description
I want to create an Authentication interceptor that whenever the JWT token is expired aborts the requests since there is no need to to keep them alive if they're going to return 401 anyway. In order to do so I need a way to access either the
AbortController
or theabort()
function in theMiddlewareOnRequest
onRequest
callback.Proposal
Instantiate a
new AbortController()
and expose either the controller itself or itsabort()
function in theMiddlewareOnRequest
onRequest
callback.Example of
AbortController
usage:Checklist
The text was updated successfully, but these errors were encountered: