swagger-typescript-api
swagger-typescript-api copied to clipboard
Authenticate with Bearer token in header
I generated a client library for a swagger file that suggests the API required a JWT Bearer token.
I can't see to figure out how to supply this bearer token \ header to the client library such that it sends it to the server.
Can someone please point me at an example?
one of options:
const api = new Api<string>({
secure: true,
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
securityWorker: accessToken =>
accessToken ? { headers: { Authorization: `Bearer ${accessToken}` } } : {},
});
// call this where you have token.
api.setSecurityData(YOUR_TOKEN);
then each api.someResource(...)
will be called with token in the header