Skip to content

Aborting requests with expired tokens from the Authentication Middleware #1985

Open
@darkbasic

Description

@darkbasic

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 the abort() function in the MiddlewareOnRequest onRequest callback.

Proposal

Instantiate a new AbortController() and expose either the controller itself or its abort() function in the MiddlewareOnRequest onRequest callback.

const authInterceptor: Middleware = {
  async onRequest({ request, controller, abort }) {
    // Use either abort() or controller.abort()
  }
}

Example of AbortController usage:

const controller = new AbortController()
const signal = controller.signal
fetch(urlToFetch, {
    method: 'get',
    signal: signal,
})
controller.abort()

Checklist

Metadata

Metadata

Assignees

Labels

PRs welcomePRs are welcome to solve this issue!enhancementNew feature or requestgood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-fetchRelevant to the openapi-fetch library

Type

No type

Projects

Status

Accepted

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions